maxwellsandstein maxwellsandstein - 1 month ago 7
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

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)