tags:

views:

65

answers:

2

Hi everyone,

I know that when iphone application goes to background, these methods are called:

- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillResignActive:(UIApplication *)application

what method(s) are called when application appears from background?

are there any methods in ViewController which are called?

thanks

+2  A: 
– applicationDidBecomeActive:
– applicationWillEnterForeground:

Oops didnt read your question properly. These two methods are in the UIApplicationDelegate

– viewWillAppear:
– viewDidAppear:

And those are in UIViewController

willcodejavaforfood
Ok, thanks, anything in view controller? I'm looking for something similar to `- (void)viewWillAppear:(BOOL)animated and - (void)viewDidAppear:(BOOL)animated` ?
Burjua
`- (void)viewWillAppear:(BOOL)animated and - (void)viewDidAppear:(BOOL)animated` aren't called unfortunately
Burjua
@Burjua - Sorry, but look at Ole Bergemann's answer :)
willcodejavaforfood
+2  A: 

Along with the applicationDidBecomeActive: and applicationWillEnterForeground: messages sent to the application delegate, the OS will also send corresponding UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification notifications.

You can have your view controller listen to these notifications:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(appWillEnterForegroundNotification:) 
                                             name:UIApplicationWillEnterForegroundNotification 
                                           object:nil];

Don't forget to remove yourself as an observer before your view controller gets destroyed.

Ole Begemann
+1 OK I stand corrected. Burjua you need to use NSNotificationCenter and register your viewControllers to listen to those notifications :)
willcodejavaforfood
ok, thanks for great answer)
Burjua