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