从后台打开应用程序时未调用ViewDidAppear

从后台打开应用程序时未调用ViewDidAppear,第1张

从后台打开应用程序时未调用ViewDidAppear

我对事件的确切顺序感到好奇,所以我对应用程序进行了如下检测:(@
Zohaib,您可以使用下面的NSNotificationCenter代码来回答您的问题)。

// AppDelegate.m- (void)applicationWillEnterForeground:(UIApplication *)application{    NSLog(@"app will enter foreground");}- (void)applicationDidBecomeActive:(UIApplication *)application{    NSLog(@"app did become active");}// ViewController.m- (void)viewDidLoad{    [super viewDidLoad];    NSLog(@"view did load");    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];}- (void)appDidBecomeActive:(NSNotification *)notification {    NSLog(@"did become active notification");}- (void)appWillEnterForeground:(NSNotification *)notification {    NSLog(@"will enter foreground notification");}- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    NSLog(@"view will appear");}- (void)viewDidAppear:(BOOL)animated {    [super viewDidAppear:animated];    NSLog(@"view did appear");}

在启动时,输出如下所示:

2013-04-07 09:31:06.505 myapp[15459:11303] view did load2013-04-07 09:31:06.507 myapp[15459:11303] view will appear2013-04-07 09:31:06.511 myapp[15459:11303] app did become active2013-04-07 09:31:06.512 myapp[15459:11303] did become active notification2013-04-07 09:31:06.517 myapp[15459:11303] view did appear

输入背景,然后重新输入前景:

2013-04-07 09:32:05.923 myapp[15459:11303] app will enter foreground2013-04-07 09:32:05.924 myapp[15459:11303] will enter foreground notification2013-04-07 09:32:05.925 myapp[15459:11303] app did become active2013-04-07 09:32:05.926 myapp[15459:11303] did become active notification


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5049184.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存