views:

57

answers:

1

I have a tabbar application that has one screen that displays statistics based on the data presented in the tableviews of over tab screens. I would like to refresh this view once the stats view becomes selected again. I have implemented the tabbarcontrollerdelegate protocol to take an action when the viewcontroller.tabbaritem.title isequaltostring:@"foo". which works fine for my nslog statement but when i try and trigger the viewcontroller to execute the viewdidload method it never happens. And the code to refresh the stats view is in the viewdidload method.

From my AppDelegate

- (void)tabBarController:(UITabBarController*)tabBarController didEndCustomizingViewControllers: (NSArray*)viewControllers changed:(BOOL)changed
{
}

- (void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController {  

    if([viewController.tabBarItem.title isEqualToString:@"Summary"]) {
        NSLog(@"didSelectViewController %@", viewController.tabBarItem.title);
        [viewController viewDidLoad]; //FAIL
    }

}
A: 

Never call viewDidLoad by yourself. That is a delegate method that is sent to the view controller after the view has loaded, you shouldn't call it manually.

In this case, view controllers that have views which are managed by a tab bar controller are sent the viewWillAppear:, viewDidAppear:, viewWillDisappear: and viewDidDisappear.

You should should use these methods to perform actions when your views are shown and hidden.

Example: implement viewDidAppear: and refresh your stats view.

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated]; // don't forget to call super, this is important

    // do your refreshing here
}
Jasarien