tags:

views:

821

answers:

1

I am building an app, which has TabBarController, and each tab view has navigation view controller. When user click tab, I'd like the relavent navigation view controller to "reset" to the root panel.

In my code, I uses the following way to initialize the tab and navigation controller.

viewController1 = [[MyFirstController alloc] init];               
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];

viewController2 = [[MySecondController alloc] init];   
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];


tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; 

    Then appears that all the tab and navigation controller is working automatically. I am not sure where to cut in to let navigation controller view to reset when it is selected.

Thanks.

+1  A: 

The navigation controller is sent a viewWillAppear message by the system, so you can implement the method to do the resetting.. Another option would be to use the tab bar controller's selectedViewController method to retrieve the selected navigation controller.. Hope that helps..