I want to have a button on my navigation bar \"Reset\" and I would like this to be connected to an IBAction
to sort of \"restart\" the controller.
I ha
If you embed navigation controller to your view controller then you can use this code:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController")
let viewcontrollers = self.navigationController.viewControllers
viewcontrollers.removeLast()
viewcontrollers.append(vc)
self.navigationControllers?.setViewControllers(viewcontrollers, animate: true)
This is how I do it in Swift 2.1 with my Home view inside a UINavigationController
:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let homeVC = storyboard.instantiateViewControllerWithIdentifier("HomeViewController")
self.navigationController?.presentViewController(homeVC, animated: false, completion: nil)
self.navigationController?.dismissViewControllerAnimated(false, completion: nil)
You can change rootViewController of your application:
UIApplication.shared.keyWindow?.rootViewController = UIViewController()