繁体   English   中英

没有在条件语句中执行Segue

[英]Segue not being performed in a conditional statement

我目前正在尝试获取条件语句以使用performSegue(withIdentifier:sender:) 目前,我没有收到任何错误,但未执行segue。 该项目使用Facebook的SDK,因此在用户登录时会调用loginButton() (这部分工作,控制台将显示“用户已登录”,确认SDK是否运行正常)

标识符在情节提要中的拼写正确

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")
    }

}

这就是情节提要的样子 故事板

一旦条件为真,我如何获得执行segue的服务?

以此替换在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