在Appdelegate的Storyboard中以编程方式为UINavigationcontroller设置rootViewcontroller [英] Programmatically set rootViewcontroller for UINavigationcontroller in Storyboard in Appdelegate

查看:258
本文介绍了在Appdelegate的Storyboard中以编程方式为UINavigationcontroller设置rootViewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NSUserdefaults中有一个值.我正在使用storyboard,它嵌入在UINavigationController中.

I have a value in NSUserdefaults. I am using storyboard, it is embedded in 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;
}

如何根据检索到的值为UINavigationController设置rootViewController.有人可以帮帮我吗?

How can I set the rootViewController for the UINavigationController based on the value that is retrieved .Can anyone please help me out?

推荐答案

您可以按照if/else条件使用ViewController创建UINavigationController的对象,并将导航控制器设置为AppDelegate中window的rootViewController属性,如下所示:

You can create an object of UINavigationController with your ViewController as per if/else condition and set the navigation controller as rootViewController property of window in AppDelegate as follows:

LoginViewController *loginController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"loginController"]; //or the homeController
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginController];
self.window.rootViewController = navController;

这篇关于在Appdelegate的Storyboard中以编程方式为UINavigationcontroller设置rootViewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆