views:

182

answers:

2

Hi,

I have a tab bar controller and in both tab bar items i have a nav controller in each. I would like that whenever a user goes away and back to a tab bar item it resets the nav controller.

If I've been navigating in one of the tab bar and then i press another tab item and go back it takes me to the beginning of the navigation.

Any ideas?

Thanks,

+1  A: 

Set yourself to be the delegate of the tabBarController, and whenever you get a -tabBarController:shouldSelectViewController: message, call -popToRootViewController on your tab's navigation controller.

Ben Gottlieb
ok i got almost all but how to set myself as the delegate.. The project has appDelegate. How do you set the delegate and where should i do it??I was trying to do it in the viewDidUnload of the nav controller
gvalero87
You need to really understand delegates to make much headway in Objective C. Take a look at the documentation for the UITabBarController, but basically: controller.delegate = self.
Ben Gottlieb
I'll post my answer, what worked for me... I try reading apple's documentation for delegates but i didn't understand much beyond the general meaning. That is, that delegates it's a part of the code that you can call from everywhere and it does an action returning something to the caller.
gvalero87
A: 

Here is what it works for me...

I made the appDelegate a UITableBarViewControllerDelegate too.

@interface InterfacesAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

After, In IB I connected the tabbarcontrollerDelegate to the appDelegate. In this case Interfaces App Delegate

As Ben said, I then implemented the abBarController:shouldSelectViewController under InterfacesAppDelegate.m

gvalero87