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

Zhen picture Zhen · Aug 12, 2011 · Viewed 7.9k times · Source

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?

Answer

phi picture phi · Aug 12, 2011

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.