ViewController 生命周期

单个viewController的生命周期

- initWithCoder:(NSCoder *)aDecoder:(如果使用storyboard或者xib)
- loadView:加载view
- viewDidLoad:view加载完毕
- viewWillAppear:控制器的view将要显示
- viewWillLayoutSubviews:控制器的view将要布局子控件
- viewDidLayoutSubviews:控制器的view布局子控件完成  
- viewDidAppear:控制器的view完全显示
- viewWillDisappear:控制器的view即将消失的时候
- viewDidDisappear:控制器的view完全消失的时候
- dealloc 控制器销毁

 

两个控制器AB进行跳转调用顺序:

A控制器先展示调用

 - [ViewControllerA loadView]
 - [ViewControllerA viewWillAppear:]
 - [ViewControllerA viewWillLayoutSubviews]
 - [ViewControllerA viewDidLayoutSubviews]
 - [ViewControllerA viewDidAppear:]

 

B控制器跳转调用顺序

 - [ViewControllerB loadView]
 - [ViewControllerB viewDidLoad]
 - [ViewControllerA viewWillDisappear:]
 - [ViewControllerB viewWillAppear:]
 - [ViewControllerB viewWillLayoutSubviews]
 - [ViewControllerB viewDidLayoutSubviews]
 - [ViewControllerA viewDidDisappear:]
 - [ViewControllerB viewDidAppear:]

 

B控制器返回A顺序

 - [ViewControllerB viewWillDisappear:]
 - [ViewControllerA viewWillAppear:]
 - [ViewControllerB viewDidDisappear:]
 - [ViewControllerA viewDidAppear:]

 

posted @ 2021-11-25 16:04  黄增松  阅读(36)  评论(0编辑  收藏  举报