我有价值NSUserdefaults
.我正在使用storyboard
,它嵌入在UINavigationController
.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if([[NSUserDefaults standardUserDefaults]objectForKey:@"isLoggedIn"]){ //show home page here }else{ // show login view } }
我可以使用打开应用程序URL
还
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { NSString *text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; if(text.length > 0){ // show home page }else { // show settings page } return YES; }
如何根据检索到的值设置rootViewController
for UINavigationController
.任何人都可以帮帮我吗?
您可以根据if/else条件使用ViewController创建UINavigationController对象,并将导航控制器设置为AppDelegate中窗口的rootViewController属性,如下所示:
LoginViewController *loginController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"loginController"]; //or the homeController UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginController]; self.window.rootViewController = navController;