标签:log 编码 lap 上下级 rbo TE elf nss nim
-(void)loadView{
NSLog(@"ViewController loadView");
}
当loadView将view加载完成,会调用viewDidLoad方法,该方法在UIVIewController初始化过程中只会执行一次,在该方法中可以进行页面相关的初始化。
当app有多级ViewController,pop操作后都会调用即将出现的ViewController的该方法,如果每次ViewController的出现都需要刷新页面,可在该方法中实现。
ViewController的view即将对subviews进行布局。
ViewController的view对subviews的布局完成。
在view被添加到视图层级中以及多视图,上下级视图切换时调用这个方法,在这里可以对正在显示的视图做进一步的设置。
页面之间push或者pop时都会调用。
页面之间push或者pop时都会调用。
在该方法中可以处理需要手动释放的东西,比如观察者的移除。
由于我编码习惯是纯代码布局,所以对xib布局和storyboard布局的相关方法未加研究,代码如下
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"ViewController viewDidLoad");
self.view.backgroundColor = [UIColor whiteColor];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"ViewController viewWillAppear");
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"ViewController viewDidAppear");
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"ViewController viewWillDisappear");
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"ViewController viewDidDisappear");
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
NSLog(@"ViewController viewWillLayoutSubviews");
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(@"ViewController viewDidLayoutSubviews");
}
(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
打印结果:
ViewController viewDidLoad
ViewController viewWillAppear
ViewController viewWillLayoutSubviews
ViewController viewDidLayoutSubviews
ViewController viewDidAppear
以上只是显示一个页面的代码和打印结果,下面我们来看一下页面间的跳转时,生命周期执行的顺序。
从A页面调转到B页面,A页面代码:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"A viewWillAppear");
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"A viewDidAppear");
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"A viewWillDisappear");
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"A viewDidDisappear");
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
NSLog(@"A viewWillLayoutSubviews");
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(@"A viewDidLayoutSubviews");
}
-(void)touchesBegan:(NSSet
B页面代码:
-(void)dealloc{
NSLog(@"B dealloc");
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"B viewWillAppear");
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"B viewDidAppear");
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"B viewWillDisappear");
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"B viewDidDisappear");
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
NSLog(@"B viewWillLayoutSubviews");
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(@"B viewDidLayoutSubviews");
}
-(void)touchesBegan:(NSSet
}
从A页面跳转到B页面,再从B页面回到A页面,打印结果:
A viewDidLoad
A viewWillAppear
A viewWillLayoutSubviews
A viewDidLayoutSubviews
A viewDidAppear
************************跳转啦****************************
B viewDidLoad
A viewWillDisappear
B viewWillAppear
B viewWillLayoutSubviews
B viewDidLayoutSubviews
A viewDidDisappear
B viewDidAppear
************************回去啦****************************
B viewWillDisappear
A viewWillAppear
B viewDidDisappear
A viewDidAppear
B dealloc
标签:log 编码 lap 上下级 rbo TE elf nss nim
原文地址:https://www.cnblogs.com/zhanqin/p/9186379.html