-->

Change initial view controller after first launch

2020-02-15 05:34发布

问题:

I have a two-view login to my app where a user enters two views worth of info. After the user has entered that info I want change which view is the initial view controller, and have the login view be a settings-like page.

How can I change the initial view controller after the user has passed a certain point in the app?

回答1:

For one of my apps, where I did similar to this, I have my "main" view controller check on viewDidLoad for a setting in the default settings that would indicate if the user had signed in. If they hadn't, I immediately pushed the loginViewController without animation and the user filled in the appropriate forms. When that was dismissed, I reloaded the view in my main view controller.

My client liked the app and it looked nice.



回答2:

If the user has already "passed a certain point", then what you change to can't be "initial" view controller, can it? The "initial" view controller is the view controller shown on launch.

Do you mean that you want a different view to appear first on subsequent launches? Then write something into the NSUserDefaults that you can check on subsequent launches so that you can start with a different window.rootViewController? Like this (changing all the names) in your app delegate's applicationDidFinishLaunching:

if ([[NSUserDefaults standardDefaults] valueForKey: @"loginDone"])
    self.window.rootViewController = 
        [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
            instantiateViewControllerWithIdentifier:@"secondVC"];

Or do mean that you just want to navigate away from the login stuff and never return? Then use a presented view controller and just never dismiss it.