Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C: How to disable user interaction to all of tab bars except one?

As what the title suggests, I would like to be able to lock all my tab bars except for one. And only after the user completes an action will I enable all the rest of the tab bars. How can I do that?

like image 289
Zhen Avatar asked Dec 02 '22 02:12

Zhen


1 Answers

I haven't tried it, but according to the docs, you can return NO from the tabBarController:shouldSelectViewController: delegate.

[UPDATE] I just tried that out of curiosity - it seems to work fine. Create a new project from the "Tab bar application" template and then go to the -viewDidLoad of your FirstViewController. Add this line:

[self.tabBarController setDelegate:self];

and then implement the delegate method:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (userHasCompletedAction) {
        return YES;
    }
    return NO;
}

Don't forget to conform to <UITabBarControllerDelegate> in your .h file!

Hope that helps.

like image 136
phi Avatar answered Dec 03 '22 15:12

phi