简体   繁体   English

没有在条件语句中执行Segue

[英]Segue not being performed in a conditional statement

I'm currently trying to get a conditional statement to use performSegue(withIdentifier:sender:) . 我目前正在尝试获取条件语句以使用performSegue(withIdentifier:sender:) Currently, I receive no error but the segue is not performed. 目前,我没有收到任何错误,但未执行segue。 The project is using Facebooks SDK so loginButton() is called when the user logs in (this part works, the console prints "user is logged in" which confirms that SDK if functioning properly) 该项目使用Facebook的SDK,因此在用户登录时会调用loginButton() (这部分工作,控制台将显示“用户已登录”,确认SDK是否运行正常)

The identifier is spelled correctly within the storyboard 标识符在情节提要中的拼写正确

class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {


    override func viewDidLoad() {
        super.viewDidLoad()

        let loginButton = FBSDKLoginButton()
        loginButton.frame = CGRect(x: 15, y: view.frame.maxY - 50, width: view.frame.width - 32, height: 32)
        view.addSubview(loginButton)

        loginButton.delegate = self
    }

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
    {
        if error != nil
        {
            print(error)
            return
        }
        else
        {
            print("user is logged in")
        }
        performSegue(withIdentifier: "postToView", sender: self)

    }

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
    {
        print("logged out")
    }

}

This is what the storyboard looks like 这就是情节提要的样子 故事板

How can I get it to perform the segue once the conditional is true? 一旦条件为真,我如何获得执行segue的服务?

Replace the call to segue in loginButton() with this. 以此替换在loginButton()中进行segue的调用。

DispatchQueue.main.async {
    [unowned self] in
    self.performSegueWithIdentifier("postToView", sender: self)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM