0

Is there a way to pop the view controller when the user switches tabs?

I have a tabbar with a navigationController on one of the tabs. The user selects a row in a table which pushes a viewController onto the navigationController containing the table. Then the user switches tabs to a new view. In the new view he hits a button that brings him back to the table tab. The problem is that the table inside the navigationController still has a view pushed onto it.

Abizern
  • 146,289
  • 39
  • 203
  • 257
Bryan
  • 17,201
  • 24
  • 97
  • 123

1 Answers1

2

Take a look at the UITabBarControllerDelegate in your situation you could call:

[navigationController popToRootViewControllerAnimated:NO];

when the tabbarcontroller calls it's didSelectViewController delegate method

klaaspieter
  • 2,665
  • 1
  • 27
  • 32
  • I never created a class for the navigationController. I just created a navController initialized with the rootViewController, added it to the tabBar, and then released the navController. Where do I find the delegate? Do I have to create a class for it? – Bryan Sep 23 '09 at 20:30
  • Do I write navController.delegate = self; and put didSelectViewController in the same class? – Bryan Sep 23 '09 at 21:01
  • You need to set the delegate of the tabbarcontroller not the delegate of the navController. Just say `tabController.delegate = navController;` and implement the tab bar controller delegate methods in your navigation controller subclass. – klaaspieter Sep 24 '09 at 07:27