views:

18

answers:

2

HI

How can I detect when I return to a view? I have an iPad app in development and I want to do something upon returning to a certain view. How can I do this?

Thanks.

A: 

If you're using UITabBarController you can take a look at UITabBarControllerDelegate protocol:

– tabBarController:didSelectViewController:

If you're using UINavigationController then the corresponding delegate protocol is UINavigationControllerDelegate and the method:

– navigationController:didShowViewController:animated:

Nevin
Ok, thanks for pointing me in the right direction. But lets say I want to to set a bool to TRUE upon returning to view 1 from view 2, how do I do it?
Josh Kahane
A: 

Override the -viewWillAppear: or -viewDidAppear: method in the UIViewController subclass that manages the view. For example:

@implementation MyController

- (void)viewDidAppear:(BOOL)animated
{
    // Do whatever you like here, for example...
    [self setSomeBOOL:YES];

    // Call super (per Apple's documentation).
    [super viewDidAppear:animated];
}

@end
jlehr