views:

696

answers:

4
+1  Q: 

Tab bar controller

Hi,

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!

A: 

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
A: 

Dear,

I have the call: [theTableView reloadData]; in method "viewWillAppear".

For this i don't know what can I do.

Thanks

A: 

Dear,

The thing I'm doing is:

In my navigation Controller I have a View Controller (like tableview) and when i click in one row, in the "didSelectRowAtIndexPath" method I create another View Controller calling "myController" and i push this element like this ( [[self navigationController] pushViewController:myController animated:YES];)

Then I think the problem is not to reload the table view in the method viewWillAppear, it's to take out from the screen the second view controller that I insert.

I'm rigth?

Thanks

+2  A: 

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