【发布时间】:2011-06-12 15:05:01
【问题描述】:
假设有人正在使用我的应用程序并更改设置包中的设置,当他们返回我的应用程序时,我希望根据这些设置更新我的视图(通过我的更新方法)。我尝试了很多不同的方法,但我就是无法让它发挥作用。
为我的 iPhone 应用实现这种行为的最佳方式是什么?
【问题讨论】:
假设有人正在使用我的应用程序并更改设置包中的设置,当他们返回我的应用程序时,我希望根据这些设置更新我的视图(通过我的更新方法)。我尝试了很多不同的方法,但我就是无法让它发挥作用。
为我的 iPhone 应用实现这种行为的最佳方式是什么?
【问题讨论】:
在您的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.
*/
}
那么你就可以随心所欲地做任何事情了。
【讨论】:
值得注意的是,您不仅限于 AppDelegate;您可以使用NSNotification 从代码中的任何位置监听这些事件。有关如何收听UIApplicationDidBecomeActiveNotification 的更多详细信息,请参阅this answer。
【讨论】: