首页 > 解决方案 > Facebook SDK:UINavigationController 没有成员“推送”

问题描述

我正在使用 Facebook 的 SDK 允许用户使用 Facebook 登录我的应用程序。登录按钮完美运行。它允许用户登录和退出并找到正确的配置文件。但是,当用户登录时,我需要应用程序显示不同的视图控制器,代码如下:

override func viewDidLoad()
    {
        super.viewDidLoad()
        
        var loginButton = FBLoginButton(permissions: [ .publicProfile ])
        
        let screenSize:CGRect = UIScreen.main.bounds
        let screenHeight = screenSize.height // real screen height
        //let's suppose we want to have 10 points bottom margin
        let newCenterY = screenHeight - loginButton.frame.height - 20
        let newCenter = CGPoint(x: view.center.x, y: newCenterY)
        loginButton.center = newCenter

        view.addSubview(loginButton)
        
        if(AccessToken.current != nil) {
            let storyboard = UIStoryboard(name: "Logged In", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "Logged In")
            self.navigationController?.push(vc, animated: true) // this is the error line
        }
        
        // Extend the code sample "1. Add Facebook Login Button Code"
        // In your viewDidLoad method:
        loginButton = FBLoginButton(permissions: [ .publicProfile, .email, .userFriends ])
    }

这是错误消息:“UINavigationController”类型的值没有成员“推送”

我正在使用最新的 SDK 版本。所以不知道怎么回事?

标签: iosswiftfacebook

解决方案


你必须使用self.navigationController?.pushViewController(VC, animated: true)而不是push

let vc = self.storyboard?.instantiateViewController(withIdentifier: "Logged In") as NextViewController
        self.navigationController?.pushViewController(VC, animated: true)

推荐阅读