当应用程序激活时调用该applicationDidBecomeActive
方法,有没有办法可以为某个 UIViewController 执行此方法?我知道有viewDidAppear
视图控制器,但我正在寻找当应用程序再次激活并且在某个 UIViewController 上时调用的方法。我怎样才能做到这一点?
问问题
7987 次
1 回答
30
您可以收听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
于 2013-06-16T11:27:07.263 回答