当应用程序进入前台时,不会调用 ViewDidAppear/ViewWillAppear。要处理进入前台的应用程序,您需要创建一个通知。
在 Appdelegate 中将以下代码添加到 applicationWillEnterForeground:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName: @"UIApplicationWillEnterForegroundNotification" object: nil];
}
然后在您各自的视图控制器中进行以下更改
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleEnterForeground:)
name: @"UIApplicationWillEnterForegroundNotification"
object: nil];
}
- (void) handleEnterForeground: (NSNotification*) sender
{
//Do whatever you need to do to handle the enter foreground notification
}