开发者

How to reload my view when my app becomes active again?

Let say someone is using my app and the change the settings in the settings开发者_C百科 bundle, when they come back to my app I would like my view to update (via my updating method) according to those settings. I've tried many different things but I just can't get it to work.

What is the best way to implement this kind of behavior for my iPhone app?


in your AppDelegate put these methods:

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the active state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

Then you have hooks to do whatever you want.


It's worth noting that you're not limited to the AppDelegate; you can listen for these events from anywhere in your code with an NSNotification. See this answer for more details on how to listen for UIApplicationDidBecomeActiveNotification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜