Change initial view controller after first launch of app

半城伤御伤魂 提交于 2019-12-18 09:34:51

问题


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.



来源:https://stackoverflow.com/questions/16329066/change-initial-view-controller-after-first-launch-of-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!