1

I have the next question:

In my project I have the next:

UItabbarController

  ....Some UINAvigationControllers....

 *(1) UINavigationController

      UIViewController (UItableView) - When select one row it goes to...(by push)

                  UIViewController (UItableView)

My problem is when i click in the tab bar item, I see the viewController view like last time that i saw this, and no reload to the *(1) first view another time.

Where I need to write sth for each time that i click in a tab bar item i reload the first view of this tab bar item.

Thanks!

2 Answers2

2

If I understand your question correctly, you are trying to return the navigation controller to the root element when it's tab bar item is selected.

To do this, set some object (e.g. your application delegate, but it can be some other object instead) to be the delegate for your UITabBarController. (If you use the application delegate, it will be the delegate for more than one thing, which is fine.) Then, implement the tabBarController:didSelectViewController: method. In that method, tell the selected view controller (which should be a NavigationController) to return to the root view controller.

Something like this. Add this implementation to your AppDelegate.m class:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [viewController popToRootViewControllerAnimated:NO];
}

In your .xib file, set the delegate for the TabBarController to the the AppDelegate. (If you are programmatically creating the tabBar, you'll have to do it programmatically there.)

As you suspected, trying to do this in viewWillAppear method, or anything other method, of the view controller that live in the navigation controller is not the correct approach. It is a method to perform on the navigation controller, and detected by the delegate of the tab bar.

Mickey Ristroph
  • 571
  • 1
  • 5
  • 11
0

Try putting your callback code to reload the view in the viewWillAppear or viewDidAppear methods. These are both called every time a view controller displays it's view on the screen.

Also feel free to copy and paste your actual code, it usually makes things easier on our end :)

Tim Bowen
  • 677
  • 6
  • 17