iPhone UITabbar item double-click pops controllers

iphone, tabbar, uitabbarcontroller, uitabbaritem

Solution

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;
}

Problem

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?

Original source