The view’s life cycle
- (void)viewDidLoad {[super viewDidLoad]; NSLog(@"%@ ---> %s", self.class, __func__); } // View will display - (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated]; NSLog(@"%@ ---> %s", self.class, __func__); } - (void)viewDidAppear:(BOOL)animated {[super viewDidAppear:animated]; NSLog(@"%@ ---> %s", self.class, __func__); } / / view is about to disappear - (void) viewWillDisappear: (BOOL) animated {[super viewWillDisappear: animated]; NSLog(@"%@ ---> %s", self.class, __func__); } / / view has disappeared - (void) viewDidDisappear: (BOOL) animated {[super viewDidDisappear: animated]; NSLog(@"%@ ---> %s", self.class, __func__); }Copy the code
Navigation controller life cycle
OneViewController --> -[MainViewController viewDidLoad] OneViewController --> -[MainViewController ViewWillAppear :] OneViewController --> -- [MainViewController viewDidAppear:] -[MainViewController viewWillDisappear:] TwoViewController ---> -[MainViewController viewDidLoad] TwoViewController ---> -[MainViewController viewWillAppear:] OneViewController ---> -[MainViewController viewDidDisappear:] TwoViewController --> [MainViewController viewDidAppear:] TwoViewController --> -- [MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] TwoViewController ---> -[MainViewController ViewDidDisappear :] OneViewController --> -- [MainViewController viewDidAppear:] -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] TwoViewController --> -- [MainViewController viewDidDisappear:] OneViewController --> -- [MainViewController viewDidAppear:] Drop does not return TwoViewController ---> -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] OneViewController ---> -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewDidDisappear:] TwoViewController ---> -[MainViewController viewWillAppear:] TwoViewController --> -- [MainViewController viewDidAppear:] *** The first time the TabBar controller life is displayed OneViewController --> -- [MainViewController viewDidLoad] OneViewController ---> -[MainViewController viewWillAppear:] OneViewController ---> -[MainViewController ViewDidAppear :] twoVc OneViewController --> -- [MainViewController viewWillDisappear:] TwoViewController --> -[MainViewController viewDidLoad] TwoViewController ---> -[MainViewController viewWillAppear:] OneViewController ---> -[MainViewController viewDidDisappear:] TwoViewController --> -- [MainViewController viewDidAppear: TwoViewController ---> -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] TwoViewController ---> -[MainViewController viewDidDisappear:] OneViewController ---> -[MainViewController viewDidAppear:] -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] TwoViewController ---> -[MainViewController ViewDidDisappear :] OneViewController --> -- [MainViewController viewDidAppear:] -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewWillAppear:] OneViewController ---> -[MainViewController viewWillDisappear:] OneViewController ---> -[MainViewController viewDidDisappear:] TwoViewController ---> -[MainViewController viewWillAppear:] TwoViewController ---> -[MainViewController viewDidAppear:]Copy the code
The view’s life cycle
// it can be called in an appropriate method in UIView like a timer or something // it's going to move to the superview - (void)willMoveToSuperview:(UIView *)newSuperview {NSLog(@"%@", newSuperview); NSLog(@"%@ --> %s", self.class, __func__); } // Already moved to the superview - (void)didMoveToSuperview {[super didMoveToSuperview]; NSLog(@"%@ --> %s", self.class, __func__); } / / is going to move to the window - (void) willMoveToWindow newWindow: (UIWindow *) {[super willMoveToWindow: newWindow]; NSLog(@"%@ --> %s", self.class, __func__); } // Already moved to window - (void)didMoveToWindow {[super didMoveToWindow]; NSLog(@"%@ --> %s", self.class, __func__); }Copy the code