just found out something: If you have a Tabbar combined with a NavigationController (that has some views on it's stack) and you double click the TabBarItem, the view pops to the first ViewController, whether you like it or not.
Is there a way to prevent this?
You probably should not prevent this behavior. It's a standard iPhone UI convention, like tapping the status bar to scroll to the top of a scroll view.
If you really want to do it, you should implement the UITabBarController
delegate method -tabBarController:shouldSelectViewController:
, like mckeed mentioned. If you have more than five tabs, however, the selectedViewController
may be a view controller that is in the "More" section, but vc
will be [UITabBarController moreNavigationController]
. Here's an implementation that handles that case:
- (BOOL)tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
UIViewController *selected = [tbc selectedViewController];
if ([selected isEqual:vc]) {
return NO;
}
if ([vc isEqual:[tbc moreNavigationController]] &&
[[tbc viewControllers] indexOfObject:selected] > 3) {
return NO;
}
return YES;
}
I just ran into this problem myself and found a way to do it. Make a delegate for your UITabBarController and implement tabBarController:shouldSelectViewController:
to prevent selecting the same controller:
- (BOOL) tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
return tbc.selectedViewController != vc;
}
You can also add more complicated logic if you only want to prevent it in some cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With