问题描述
我在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)