簡體   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