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?
Asked
Active
Viewed 8,046 times
3 Answers
15
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.

phi
- 10,634
- 6
- 53
- 88
-
thanks for your response :) Can I check if you know how I can select which tabs to disable? I need to disable all but one tab. In this method, I am not sure if you can specify that? – Zhen Aug 12 '11 at 15:39
-
@Zhen you have both the tabBarController and the viewController as arguments, so based on your code you can select the desired ones. Check the properties of these classes, for example you could use 'selectedIndex'. – phi Aug 15 '11 at 06:29
4
You have to implement this method
- (void)tabBarController:(UITabBarController *)tabBarController1 didSelectViewController:(UIViewController *)viewController {
if ([tabBarController1 selectedIndex]==0) {
UITabBarItem *tabBarItem = [[[[self tabBarController]tabBar]items] objectAtIndex:1];
[tabBarItem setEnabled:FALSE];
}
}
You have to do something like this for disabling your required tabbar items.

Gypsa
- 11,230
- 6
- 44
- 82