So I have a login view, after successful login it goes to the first view of a navigation controller, then the user can go deeper to a settings view and then to a logout view. This logout should take the user back to the login view (which is not part of the navigation controller). It works with this code:
let loginViewController = self.storyboard!.instantiateViewControllerWithIdentifier("Login") as? LoginViewController
self.navigationController!.pushViewController(loginViewController!, animated: true)
But the login view displays the navigation bar at the top, which it shouldn't do, maybe there is something other than self.navigationController!.pushViewController
that I should be using?
SWIFT: You should use an unwind segue.
First of all, put the following line in your FirstViewController
:
@IBAction func prepareForUnwind(segue: UIStoryboardSegue) { }
The function actually doesn't have any code inside it.
LogoutViewController
by control-dragging from the yellow button to the Exit button. Like this:Select the unwind segue created for FirstViewController
.
Change the segue identifier:
Go to the code of LogoutViewController
and just call the unwind segue normally:
self.performSegueWithIdentifier("unwindToViewController1", sender: self)
Swift 4
self.performSegue(withIdentifier: "unwindToViewController1", sender: self)