TabBarController, overwriting shouldSelectViewController to do a segue
Asked Answered
C

1

0

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!!!!

Caudate answered 6/3, 2012 at 18:17 Comment(0)
C
2

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 :)

Caudate answered 8/3, 2012 at 17:27 Comment(1)
This didn't work for me on iPhone. I had to do the following: Set modalPresentationStyle to UIModalPresentationFormSheet and set modalTransitionStyle to UIModalTransitionStyleCrossDissolve.Ayrshire

© 2022 - 2024 — McMap. All rights reserved.