在视图控制器从生到死的过程中,会经历以下进程
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view from its nib. 4 } 5 6 - (void)viewWillAppear:(BOOL)animated{ 7 [super viewWillAppear:animated]; 8 NSLog(@"视图将要显示"); 9 } 10 - (void)viewDidAppear:(BOOL)animated{ 11 [super viewDidAppear:animated]; 12 NSLog(@"视图已经显示"); 13 } 14 15 - (void)viewWillLayoutSubviews{ 16 [super viewWillLayoutSubviews]; 17 NSLog(@"viewWillLayoutSubviews"); 18 } 19 - (void)viewDidLayoutSubviews{ 20 [super viewDidLayoutSubviews]; 21 NSLog(@"viewDidLayoutSubviews"); 22 } 23 24 - (void)viewWillDisappear:(BOOL)animated{ 25 [super viewWillDisappear:animated]; 26 NSLog(@"视图将要移除"); 27 } 28 - (void)viewDidDisappear:(BOOL)animated{ 29 [super viewDidDisappear:animated]; 30 NSLog(@"视图已经移除"); 31 } 32 - (void)dealloc{ 33 NSLog(@"视图被销毁"); 34 }
其中最一开始被调用的应该是loadView方法,但因现阶段水平不足,不敢去复写该方法
在一次切换界面,产生以下输出结果
2016-07-01 20:36:25.001 task2[11634:670742] 视图将要显示 2016-07-01 20:36:25.005 task2[11634:670742] viewWillLayoutSubviews 2016-07-01 20:36:25.005 task2[11634:670742] viewDidLayoutSubviews 2016-07-01 20:36:25.039 task2[11634:670742] viewWillLayoutSubviews 2016-07-01 20:36:25.040 task2[11634:670742] viewDidLayoutSubviews 2016-07-01 20:36:25.050 task2[11634:670742] 视图已经显示 2016-07-01 20:36:30.011 task2[11634:670742] 视图将要移除 2016-07-01 20:36:30.520 task2[11634:670742] 视图已经移除
其中视图布局被调用两次,第一次是布局系统自己添加的控件,第二次是布局编程者添加的控件
@end
时间: 2024-10-12 14:19:25