maxwellsandstein maxwellsandstein - 1 year ago 73
Swift Question

How to get rid of navigation controller and segue to a controller before it?

Say I have a storyboard a such logInVC->navViewController->RootVC->restOfStack

If in the rootVC I want to logOut, thereby segueing to logInVC without logInVC becoming a part of my stack then how would I do this. I essentially need to get rid of the navigation controller and its stack entirely, returning to the apps launch page that comes before the navVC.

Was surprised to have trouble finding an answer to this one in Swift, would think this is quite a common problem.

Answer Source

By dismissing the root view controller of your key window, you dismiss all view controllers and go back to youe login vc assuming it's the initial view controller.

UIApplication.sharedApplication().keyWindow?.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download