I have an app with a tab bar with two tabs. One tab displays a UINavigationController, the other a UIViewController that I have customized.
What I have noticed is that if switch tabs to the UINavigationController tab then navigate a few levels deep in UITableViews, if I click on the current tab on the UITabBar the UINavigationController pops to it’s root view.
I was wondering how this takes place. It does not appear that the UINavigationController is a delegate of the UITabBar or UITabBarController, which would have been one option. The functionality is somehow automatic.
I want to implement a similar action on my UIView in the second tab, so I’d like to figure this out. Thanks!
What
UITabBarControlleris doing is that whenever you tap a already selected tab, it checks if theUIViewControllerof that tab is anUINavigationController. If it is, then pop to the rootViewController.What you want to do is to set you second tab the delegate of your
UITabBarControllerand check forWhen ever that method is fired, check if the
viewControlleris your second tab viewController and that theselectedIndex(ofUITabBarController) is 1. If that’s the case, implement your action.This works only on iOS 3.0 or later. In versions of iOS prior to version 3.0, this method is called only when the selected view controller actually changes.