gpt4 book ai didi

ios - 从后台打开应用程序时不调用 ViewDidAppear

转载 作者:IT老高 更新时间:2023-10-28 12:16:42 27 4
gpt4 key购买 nike

我有一个 View Controller ,其中我的值为 0(标签),当我从另一个 ViewController 打开该 View Controller 时,我已将 viewDidAppear 设置为 20标签。它工作正常,但是当我关闭我的应用程序并再次打开我的应用程序但值没有改变,因为 viewDidLoadviewDidAppearviewWillAppear什么都没有被调用。打开我的应用程序时如何调用电话。我必须从 applicationDidBecomeActive 做任何事情吗?

最佳答案

对事件的确切顺序感到好奇,我按如下方式检测了一个应用程序:(@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 load
2013-04-07 09:31:06.507 myapp[15459:11303] view will appear
2013-04-07 09:31:06.511 myapp[15459:11303] app did become active
2013-04-07 09:31:06.512 myapp[15459:11303] did become active notification
2013-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 foreground
2013-04-07 09:32:05.924 myapp[15459:11303] will enter foreground notification
2013-04-07 09:32:05.925 myapp[15459:11303] app did become active
2013-04-07 09:32:05.926 myapp[15459:11303] did become active notification

关于ios - 从后台打开应用程序时不调用 ViewDidAppear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15864364/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com