我想知道如何在viewController出现时知道,从UIApplication的主窗口中消失。我不想在每个UIViewController中放置代码,但是要观察UIApplication中每个viewcontroller的生命周期。
答案 0 :(得分:0)
每个视图控制器都有一个生命周期。所以每个视图控制器都有独立的生命周期方法所以你必须为每个UIViewController放置代码。在app delegate中,我们检查应用程序状态。 国家是:
委托方法:
application:didFinishLaunchingWithOptions:
applicationWillResignActive:
applicationDidBecomeActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:
查看控制器生命周期方法:
-(void)viewDidLoad:(BOOL)animated{
[super viewDidLoad:animated];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}