views:

130

answers:

1

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.

+1  A: 

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
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
Do I write navController.delegate = self;and put didSelectViewController in the same class?
Bryan
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