问题
Hi Im trying to change the tabcontroller flow, so when a user is not loged in just take him to the login view instead the settings one. My controller extends TabBarController and I set the delegate as
self.tabBarController.delegate=self;
My Code is:
- (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;
}
I never manage to do the navigation it gives an excetion :
ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.
I also tried to show the login in as a modal but it only shows a black screen:
- (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;
}
}
Can anybody help Me!!!! please!!!!
回答1:
Well I manage to fix the black modal screen (still cant d a segue that is not modal). The problem was that as I am using storyboard I have to load the view from story board as follows.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:@"login"];
[navController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:navController animated:YES];
That made the trick :)
来源:https://stackoverflow.com/questions/9589538/tabbarcontroller-overwriting-shouldselectviewcontroller-to-do-a-segue