UIViewController中的applicationDidBecomeActive? [英] applicationDidBecomeActive in UIViewController?
本文介绍了UIViewController中的applicationDidBecomeActive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当应用程序变为活动状态时,会调用 applicationDidBecomeActive
方法,有没有办法可以为某个UIViewController执行此方法?我知道视图控制器有 viewDidAppear
但是我正在搜索当应用再次变为活动状态并且在某个UIViewController上时调用的方法。我怎样才能实现这个目标?
The applicationDidBecomeActive
method gets called when the app became active, is there a way that I can do this method for a certain UIViewController? I know there is viewDidAppear
for view controllers but I'm searching for a method that is called when the app becomes active again AND is on a certain UIViewController. How can I achieve this?
推荐答案
您可以收听 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
这篇关于UIViewController中的applicationDidBecomeActive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文