I have a class MasterViewController
that loads on app startup. Inside viewDidLoad()
it checks if a user is logged in, and presents one view controller or another based on the outcome. If you aren't logged in and then proceed to do so, the app loads up a new MasterViewController
. My goal is to essentially replace the existing MasterViewController
with a new instance so it performs the check in viewDidLoad
once again. I've tried the following, and they both work:
// changing the root view controller
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds)
appDelegate.window!.rootViewController = MasterViewController()
appDelegate.window!.makeKeyAndVisible()
// using presentViewControllerAnimated
someViewController.presentViewControllerAnimated(MasterViewController(), animated: true, completion: nil)
...but while presentViewControllerAnimated
has a nice animation, changing root doesn't. More importantly, changing the root view controller doesn't destroy the existing one (at least deinit is never called..), and obviously presentViewControllerAnimated
doesn't do that either, so in both cases I have this view controller floating around that I don't want anymore.
I can just imagine some scenario where a user logs out and back in repeatedly and suddenly I have 10 MasterViewControllers on top of one another. Any way to completely purge a view controller? Or is this just totally unnecessary?
EDIT
Just remembered presentViewControllerAnimated
is for presenting a vc modally, so that's definitely not what I want. Would be nice to change the root view controller with a similar animation though. All the animations I've seen with root vc changes were pretty wonky.