Swift prepareForSegue cancel

后端 未结 3 1268
野的像风
野的像风 2020-12-25 10:22

I\'m trying to implement a login screen, when login is clicked it does the segue \"login\".

I added a prepareForSegue() override to try to cancel it if the login fai

3条回答
  •  青春惊慌失措
    2020-12-25 11:06

    You could use shouldPerformSegue and return false, therefore blocking all segues. For example:

    override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
        return false 
    }
    

    Then, once you have a successful login, call performSegue, like this:

    performSegue(withIdentifier: "YourSegueIdentifier", sender: nil)
    

    This will ensure that you will only transition to the controller when you have a login success.

提交回复
热议问题