AppDelegate,rootViewController和presentViewController [英] AppDelegate, rootViewController and presentViewController
问题描述
我正在做Facebook整合教程,如果用户对当前状态有一个有效的令牌,我想显示我的MainViewViewController,否则我想显示LoginViewController。
I'm doing the Facebook integration tutorial, I want to show my MainViewViewController if the user has a valid token for the current state otherwise I want to show LoginViewController.
MainViewAppDelegate.m
MainViewAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// To-do, show logged in view
} else {
// No, display the login page.
[self showLoginView];
}
return YES;
}
- (void)showLoginView
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginViewController* loginViewController = [mainstoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.window.rootViewController presentViewController:loginViewController animated:YES completion:NULL];
}
控制台错误:
Warning: Attempt to present <LoginViewController: 0xb492fd0> on <MainViewViewController: 0xb1bd820> whose view is not in the window hierarchy!
我不想使用NavigationController。
I don't want to use a NavigationController.
推荐答案
我有同样的问题。根据此问题的答案,我在 presentViewController:animated:completion:
之前添加了 [self.window makeKeyAndVisible]
,并将其修复为我。
I had the same issue. Based on the answer to this question, I added [self.window makeKeyAndVisible]
just before presentViewController:animated:completion:
, and that fixed it for me.
在您的情况下,showLoginView变为
In your case, showLoginView becomes
- (void)showLoginView
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:loginViewController animated:YES completion:NULL];
}
这篇关于AppDelegate,rootViewController和presentViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!