您好我正在尝试更改tabcontroller流程,因此当用户没有进入时只需将他带到登录视图而不是设置一个。我的控制器扩展了TabBarController,我将委托设置为
self.tabBarController.delegate=self;
我的代码是:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (login) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentViewController:loginViewController animated:YES completion:nil];
return NO;
} else {
return YES;
}
我从未设法进行导航,但是它提供了一个例外:
ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.
我还尝试将登录信息显示为模式,但它只显示黑屏:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (YES) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentModalViewController:navController animated:YES];
return NO;
} else {
return YES;
}
}
任何人都可以帮助我!!!!请!!!!
答案 0 :(得分:2)
好吧,我设法修复黑色模态屏幕(仍然不能是一个非模态的segue)。 问题是,当我使用故事板时,我必须从故事板加载视图,如下所示。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:@"login"];
[navController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:navController animated:YES];
这就是诀窍:)