Facebook SDK:UINavigationController 没有成员 'push'

Facebook SDK: UINavigationController has no member 'push'

我正在使用 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' 类型的值没有成员 'push'

我使用的是最新版本的SDK。所以我不知道哪里出了问题?

你试过用这个吗? -

self.navigationController?.pushViewController(vc, animated: true)

更新:

self.present(vc, animated: true, completion: nil)

试试这个。

self.navigationController?.pushViewController(vc, animated: true)

代替push()方法,您将不得不使用pushViewController()方法

self.navigationController?.pushViewController(vc, animated: true). 

注:-

您的故事板文件名不能包含 space,请删除 space。将故事板文件名重命名为 'LoggedIn' 或 'Logged_In'.

        let storyboard = UIStoryboard(name: "LoggedIn", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "Logged In")
        self.navigationController?.push(vc, animated: true) 

如何查看故事板名称和视图控制器标识符?

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

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

而不是 push() 写在下面行

self.navigationController?.pushViewController(vc, animated: true)

要更改屏幕标题,您必须设置第二个屏幕的标题 属性,

vc.title = "Logged In"