views:

305

answers:

2

The default behavior of a UITabBarController is to pop the contained UINavigationController to the root view controller when a particular tab is tapped a second time. I have a particular use case where I'm wanting this to not work automatically, and I'm having a hard time figuring out how to prevent this.

Has anyone run into this, and if so, what did you do? Do I need to subclass UINavigationController and override popToRootViewController or is there a simpler way?

+1  A: 

You might be able to accomplish this with the UITabBarControllerDelegate protocol:

- (BOOL)tabBarController:(UITabBarController *)aTabBar shouldSelectViewController:(UIViewController *)viewController

This is admittedly one of those issues that's hard to describe in an unambiguous way to find answers on Google ;).

Sean Murphy
Brilliant. I don't know how I missed that in the delegate protocol. It worked like a charm. Thanks!
NilObject
A: 

this is what I did:

  • (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    if ([[tabBarController viewControllers] objectAtIndex:[tabBarController selectedIndex]] == viewController)

        return NO;
    

    return YES;

}

regards

Ray