我的应用的第一个屏幕包含登录屏幕。我正在显示AppDelegate
的登录屏幕。
登录屏幕出现,我可以在模拟器中转到下一个屏幕。但它并不适用于设备。
在设备上,主屏幕出现一秒钟,并显示登录屏幕。我尝试更改[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
和[self.window.rootViewController presentViewController:self.navigationController animated:YES completion:nil];
的顺序,但这也不起作用。
我在iOS 9.0 iPad(设备)上运行。但是在模拟器上一切似乎都很好。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = nil;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self->_loginViewController = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = nil;
self.window.rootViewController = self->_loginViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)loginUser {
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
//load xib for iPad
mainVC = [[MainVC alloc] initWithNibName:@"MainVC~ipad" bundle:nil];
} else if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
//load xib for iPhone
mainVC = [[MainVC alloc] initWithNibName:@"MainVC~iphone" bundle:nil];
}
self.navigationController = nil;
self.navigationController = [[UINavigationController alloc] initWithRootViewController:mainVC];
dispatch_async(dispatch_get_main_queue(),^ {
// [self.window.rootViewController.navigationController popViewControllerAnimated:YES]; //not working
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil]; //not working
[self.window.rootViewController presentViewController:self.navigationController animated:YES completion:nil];
//not working
// [self.window.rootViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{
// [self.window.rootViewController presentViewController:self.navigationController animated:YES completion:nil];
// }];
});
}
答案 0 :(得分:0)
首先,你要设置LoginViewController
作为窗口的rootController,这很好。在您的登录方法中,您尝试在此处没有显示控制器时解除控制器(假设您没有提供任何其他控制器)。您可以删除该行并只显示导航控制器。
答案 1 :(得分:0)
为此,我通常会更改rootViewController
。在您的情况下,当您的用户登录时替换:
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil]; //not working
[self.window.rootViewController presentViewController:self.navigationController animated:YES completion:nil];
使用:
self.window.rootViewController = self.navigationController;
然后在用户注销时执行:
self.window.rootViewController = self.loginViewController;