views:

353

answers:

1

With multi-tasking in iOS4, the home button puts the app into background and when it comes back into foreground I want the View Controller to 'refresh' (and hence viewWillAppear to be called). I put this in the app delegate thought this should work but nothing happens

 - (void)applicationDidFinishLaunching:(UIApplication *)application {    

    //  
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
 }


 - (void)applicationWillEnterForeground:(UIApplication *)application {
    [viewController.view reloadInputViews];
 }

Can anyone help me with forcing a view controller to 'execute'/refresh when it is already showing?

A: 

You could call viewWillAppear explicitly e.g.

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [viewController.view reloadInputViews];

    [viewController viewWillAppear];
 }
Run Loop
That's so cool, I didn't even know you can do that. Tested it and it worked (in the simlulator, have other issues on device, but I don't think it is related). For other readers I was going to use the work around suggested here http://stackoverflow.com/questions/3187642/ios4-removing-app-from-memory-via-code. But I'm going with Run Loop.
munchine