Segue crashes my program. Has something to do with my NavigationController and my TabBarViewController

丶灬走出姿态 提交于 2019-11-28 14:32:05

You do not want to use a traditional segue to return to your login screen. The normal segue types always create a new copy of the destination view controller. Instead, you want to return control to the view controller that called you.

You need to set up an unwind segue on logout. Here's how.

1) In the code for ViewController add this function:

@IBAction func comeHereOnLogout(segue:UIStoryboardSegue) {
    println("Yay, Logged Out!")
}

2) Control-drag from the view controller icon at the top of your Settings View Controller to the exit icon at the top of your Settings View Controller and choose comeHereOnLogout from the pop up that appears.



Select that segue in the Document Outline and give it an Identifier in the Attributes Inspector such as "logoutSegue".


Then you can trigger this segue in code with:

self.performSegueWithIdentifier("logoutSegue", sender: self)

3) Alternatively, you can wire the unwind segue from your Logout button to the exit icon at the top of your Settings View Controller. In this case, this segue would replace your logout button action. Again, you'd want to give this segue a name such as "logoutSegue".


In this case, you'd put your logout code in prepare for segue:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "logoutSegue" {
        PFUser.logOut()
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!