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.
Yes, that’s the standard behaviour, but you can prevent it by implementing the tab bar delegate method
shouldSelectViewControllerAn example of how to do this is here Prevent automatic popToRootViewController on double-tap of UITabBarController