gpt4 book ai didi

ios - UIViewController 中的 applicationDidBecomeActive?

转载 作者:可可西里 更新时间:2023-11-01 03:02:41 26 4
gpt4 key购买 nike

applicationDidBecomeActive 方法在应用程序激活时被调用,有没有办法可以为某个 UIViewController 执行此方法?我知道有用于 View Controller 的 viewDidAppear 但我正在搜索当应用程序再次激活并且位于某个 UIViewController 上时调用的方法。我怎样才能做到这一点?

最佳答案

可以监听UIApplicationDidBecomeActiveNotification通知:

@implementation CertainViewController

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidBecomeActiveNotification:)
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
}

- (void)applicationDidBecomeActiveNotification:(NSNotification *)notification {
// Do something here
}

@end

关于ios - UIViewController 中的 applicationDidBecomeActive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17132734/

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