I wonder if its possible to set a new root VC?
My app gets init with a uinavigation controller that has a table view to be the root VC.
Then from the table view I am running another segue to a login window (present modally) If you then login you end up in the red VC/account page. What I want to do now is to set the red VC to be the new root VC of the app, and remove all underlying VC's. So that I can show a menu button/icon instead of a "Back" button
I have found this but I dont understand how to use it:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController
let navigationController = self.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewController], animated: true)
But I cannot get it to work. So is it possible to make the red vc in the picture act as the new root VC.
For swift 4.0.
In your AppDelegate.swift file in didfinishedlaunchingWithOptions method, put the following code.
Hope it will work just fine.
Swift 3 Update:-
UINavigationController has a viewControllers property, which is a NSArray, And you can replaced it with your own NSArray of view controllrs.
This can be done as show in below sample code.
And if you want to show this new root view controller you can just call UINavigationController's popToRootViewController() method.
You can use this bit of code:
Swift 3 AppDelegate file:::
once you are in the vc that you want to set as root, just add in your viewDidLoad:
*As per best practice you should check if it is already the root, if not execute the code above.