当我的应用再次变为活动状态时如何重新加载我的视图?

时间:2011-01-20 17:18:22

标签: iphone ios4

假设某人正在使用我的应用并更改设置包中的设置,当他们回到我的应用时,我希望我的视图根据这些设置更新(通过我的更新方法)。我尝试了很多不同的东西,但我无法让它发挥作用。

为我的iPhone应用程序实现此类行为的最佳方法是什么?

2 个答案:

答案 0 :(得分:6)

在你的AppDelegate中放了这些方法:

- (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.
     */
}

然后你可以随心所欲地做任何事情。

答案 1 :(得分:3)

值得注意的是,您不仅限于AppDelegate;您可以使用NSNotification从代码中的任何位置收听这些事件。有关如何收听UIApplicationDidBecomeActiveNotification的详细信息,请参阅this answer

相关问题