1

My iPhone app has a tab bar controller, and one of the tabs is a navigation controller. When the user double taps on the tab, it causes the navigation controller to pop back to the root view.

My problem is that some of the views in my navigation hierarchy have a specific bar button in their navigationItem associated with that view. So I'm programmatically setting the rightBarButtonItem based on what view was pushed to the navigationController. When the double-tap happens, it pops back to the root view, but not to the right button. The button seems to stay the same as the last view popped that had its own specific button.

So I have a mismatch of the root view with a bar button that goes with another view.

Is there a way to detect when the double tap action occurs? In that case I could reset the buttons on the nav bar to the correct ones. I tried doing it in viewWillAppear/viewDidAppear/viewDidLoad methods, but these don't seem to be called when the tab bar double tap happens.

bobfet1
  • 1,603
  • 21
  • 22
  • I'm not trying to detect a double tap on a regular button - it's a double tap on the tab bar controller tab (not anything in the view itself) – bobfet1 Aug 30 '11 at 10:52

1 Answers1

1

The safest way to ensure that you always have the right button independent of how the view was made visible (e.g., by popping a child view controller, or by double-tapping the tab bar) is to set the button each time the view becomes visible. Thus, in your root view controller:

-(void)viewWillAppear {
    //check button, change if desired
}
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • 1
    Thanks - this put me on the right track. At first I thought my viewWillAppear method was not getting called, but it turns out that if you use the initWithRootViewController method on the navigation controller, that is the view controller that will have its viewWillAppear method called when the tab bar is double-tapped. But my problem was also that the popToRootViewController method also goes back to the wrong navigationItem in some older versions of iOS, as described here: http://stackoverflow.com/questions/5902164/uinavigationitem-out-of-sync-when-using-poptorootviewcontroller – bobfet1 Aug 30 '11 at 10:54