Reputation: 29458
I have a UITabBarController. One tab is a UINavigationController where it's rootViewController is a subclass of UIViewController. In my rootViewController, in my viewDidLoad, I push the first of three ViewControllers. Based on which UISegmentedControl is pressed, I pop the old view, and I push the viewController that corresponds to the UISegmentedControl. This works for the most part.
The problem is if I'm currently in the Navigation hierarchy, if I hit the same tab again (the tab I am already looking at), it pops the current ViewController off the stack and returns to the rootViewController. I'm not sure why this is happening. I only have one place where I popViewController and I set a break point there, and it never gets called. So my assumption is that when I select the tab of the UITabBarController when I'm already on that tab, it returns to the rootViewController. Is that correct? Is there anything I can do to fix this issue? Thanks.
Upvotes: 2
Views: 1542
Reputation: 710
Yes, that's the standard behaviour, but you can prevent it by implementing the tab bar delegate method shouldSelectViewController
An example of how to do this is here Prevent automatic popToRootViewController on double-tap of UITabBarController
Upvotes: 1
Reputation: 17408
The functionality you describe is standard of the tabbarcontroller. Some users are used to using it and may be frustrated if you disable it.
However, it is possible using the tabBarController: shouldSelectViewController delegate function. In that function you can check if the view controller wanting selection matches the one already displayed. If so, don't allow it.
Upvotes: 0