在 Appdelegate 的 Storyboard 中以编程方式为 UINavigationcontroller 设置 rootViewcontroller

Programmatically set rootViewcontroller for UINavigationcontroller in Storyboard in Appdelegate(在 Appdelegate 的 Storyboard 中以编程方式为 UINavigationcontroller 设置 rootViewcontroller)
本文介绍了在 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 打开应用程序

I can open the app using a URL also

- (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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)