让我们说别人正在使用我的应用程序,并在设置包中更改设置,当它们返回到我的应用程序时,我希望我的视图根据这些设置进行更新(通过我的更新方法)。我尝试过很多不同的东西,但我无法完成它的工作。如何重新加载我的视图时,我的应用程序再次变得活跃?
为我的iPhone应用程序实现这种行为的最佳方式是什么?
让我们说别人正在使用我的应用程序,并在设置包中更改设置,当它们返回到我的应用程序时,我希望我的视图根据这些设置进行更新(通过我的更新方法)。我尝试过很多不同的东西,但我无法完成它的工作。如何重新加载我的视图时,我的应用程序再次变得活跃?
为我的iPhone应用程序实现这种行为的最佳方式是什么?
值得注意的是,您不仅限于AppDelegate;您可以使用NSNotification
从代码中的任何位置收听这些事件。有关如何收听UIApplicationDidBecomeActiveNotification
的详细信息,请参阅this answer。
在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.
*/
}
然后,你必须挂钩,做你想做的。
有趣的是,从来不知道通知被解雇! – 2011-01-20 17:32:53