0

i have two tab bar items with two different table view with navigation controllers. by clicking on the tab1--- table1 is opening...Good. but when i did select on table1 it goes to the another view (table did select view)....every thing is good.

but the problem here is

when i am clicking on tab2 ----table 2 is opening....Good.

But again clicking on tab1------ it is not loading the table1....it is loading (table did select view) view. As the last time i left it there.

i want to open table1----on clicking on tab1......by programming.

help me

1 Answers1

1

That is the expected behaviour if you are using the tab bar controller and the navigation controller in the item of the tab bar. User will expect the tab to retain the state of the view.

If you still want to enforce the app to go back to the root view controller of the navigation controller when user goes back to the tab, you can implement the UITabBarControllerDelegate tabBarController:didSelectViewController: method. What this delegate method does is:

Tells the delegate that the user selected an item in the tab bar.

Then call the method of UINavigationController called popToRootViewControllerAnimated: when user tap on the tab. This will help you to:

Pops all the view controllers on the stack except the root view controller and updates the display.

For example:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if(viewController == yourNavigationController) {
        UINavigationController *navigationController = (UINavigationController *)viewController;
        [navigationController popToRootViewControllerAnimated:NO];
    }
}
Valent Richie
  • 5,226
  • 1
  • 20
  • 21