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开发者_如何学Go of the tab bars. How can I do that?
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.
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.
The method tabBar:didSelectItem:
in UITabBarDelegate
could help.
精彩评论