UIViewController中的applicationDidBecomeActive?

applicationDidBecomeActive程序变为活动状态时会调用applicationDidBecomeActive方法,有没有办法可以为某个UIViewController执行此方法? 我知道视图控制器有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