【问题标题】:Issue when adding a Facebook like button to my iOS app向我的 iOS 应用添加 Facebook 赞按钮时出现问题
【发布时间】:2016-03-21 20:24:08
【问题描述】:

我正在尝试使用 swift 在我的应用中添加一个 Facebook 赞按钮。这是我的代码,也是我到目前为止所采取的步骤。我想知道我是否遗漏了任何步骤,或者代码是否有问题?

1- 使用 Swift 创建了一个新的 Xcode 项目

2-在viewDiDLoad中添加以下代码

3-导入的“import Parse”和“import Social”,如下所示

4-创建桥接头文件并将FBSDKCoreKit/FBSDKCoreKit.h和FBSDKShareKit/FBSDKShareKit.h导入其中。

5-在我的框架中添加了 FBSDKCoreKit 和 FBSDKShareKit

然后我在这一行收到“预期声明”错误: likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"

这里是完整的代码:

    import UIKit
        import Parse
        import Social

        class NewsPageViewController: UIViewController {
        override func viewDidLoad() {
            super.viewDidLoad()

            var likeButton:FBSDKLikeControl = FBSDKLikeControl()
            likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
            likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
            likeButton.frame = CGRectMake(16,20, 290, 40)
            self.view.addSubview(likeButton)
    }

}

【问题讨论】:

    标签: ios facebook swift


    【解决方案1】:

    问题是我想按下一个按钮,然后显示类似按钮。所以我添加了一个 IBAction,它就像黄金一样工作!接下来对我来说是想办法改变按钮图像:) 顺便说一下,这是工作代码:

        import UIKit
        import Parse
        import Social
    
        class NewsPageViewController: UIViewController {
            override func viewDidLoad() {
            super.viewDidLoad()
            }
            @IBAction func likeOnFacebook(sender: AnyObject) {
    
                var likeButton:FBSDKLikeControl = FBSDKLikeControl()
                likeButton.objectID = "https://www.facebook.com/JCVDonline/?fref=ts"
                likeButton.likeControlStyle = FBSDKLikeControlStyle.BoxCount
                likeButton.frame = CGRectMake(16,20, 290, 40)
                self.view.addSubview(likeButton)
             }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多