I have a tab bar driven app.
The app has some view controllers that are stacked on each other the usual way.
Some of these view controllers may be top level – meaning instantiated directly from the tab bar controller. Those do not have a “back” button in their navigation bar.
Some of these can be called at many points within the call stack. Meaning they could be called from some other view controller and not directly from the tab bar.
I am looking for a smart way to determine programatically whether the current view controller currently has a “back” button in its nav bar or not.
(If it does not then I want to display some other bar item at that place.)
Any hint is appreciated. 🙂
Well… from what you are describing, I can understand that you have a
UITabBarControllerwith a list of view controller in each tab, and each view controller is a navigation controller, which further leads to new views. And you are interested in finding if a particular view is the first view or the second view, and so forth.Interestingly, there is a way to do this. The navigation controller is basically a
viewControllerarray with views added to the index of the navigationController. The first view will be in index 0. If you perform apushViewController, thenewViewControlleris placed at index 1.Just check for the index count of the
self.navigationControllerof that particular view. If it is greater than 1, you can be certain that it is not the initial view.You can also check for the
backBarButtonItemproperty, but then again, it may not be needed. TheviewControllersarray count should do.