1,在storyboard上删除预先建好的控制器,拖出NavigationController,使其rootView连接一个新建的ViewController(FKOneViewController),在FKOneViewController上放上一个button,点击button跳转到另一个新建的ViewController(FKSecondViewController)。
2,在FKOneViewController和FKSecondViewController写入代码:
1 #import "FKOneViewController.h" 2 3 @implementation FKOneViewController 4 - (void)loadView 5 { 6 [super loadView]; 7 NSLog(@"FKOneViewController---loadView"); 8 } 9 10 - (void)viewDidLoad 11 { 12 [super viewDidLoad]; 13 NSLog(@"FKOneViewController---viewDidLoad"); 14 } 15 16 - (void)viewWillAppear:(BOOL)animated 17 { 18 [super viewWillAppear:animated]; 19 NSLog(@"FKOneViewController---viewWillAppear"); 20 } 21 22 - (void)viewDidAppear:(BOOL)animated 23 { 24 [super viewDidAppear:animated]; 25 NSLog(@"FKOneViewController---viewDidAppear"); 26 } 27 28 - (void)viewWillDisappear:(BOOL)animated 29 { 30 [super viewWillDisappear:animated]; 31 NSLog(@"FKOneViewController---viewWillDisappear"); 32 } 33 34 - (void)viewDidDisappear:(BOOL)animated 35 { 36 [super viewDidDisappear:animated]; 37 NSLog(@"FKOneViewController---viewDidDisappear"); 38 } 39 40 - (void)dealloc 41 { 42 NSLog(@"FKOneViewController---dealloc"); 43 } 44 @end
1 #import "FKSecondViewController.h" 2 3 @implementation FKSecondViewController 4 - (void)loadView 5 { 6 [super loadView]; 7 8 NSLog(@"FKSecondViewController---loadView"); 9 } 10 11 - (void)viewDidLoad 12 { 13 [super viewDidLoad]; 14 NSLog(@"FKSecondViewController---viewDidLoad"); 15 } 16 17 - (void)viewWillAppear:(BOOL)animated 18 { 19 [super viewWillAppear:animated]; 20 NSLog(@"FKSecondViewController---viewWillAppear"); 21 } 22 23 - (void)viewDidAppear:(BOOL)animated 24 { 25 [super viewDidAppear:animated]; 26 NSLog(@"FKSecondViewController---viewDidAppear"); 27 } 28 29 - (void)viewWillDisappear:(BOOL)animated 30 { 31 [super viewWillDisappear:animated]; 32 NSLog(@"FKSecondViewController---viewWillDisappear"); 33 } 34 35 - (void)viewDidDisappear:(BOOL)animated 36 { 37 [super viewDidDisappear:animated]; 38 NSLog(@"FKSecondViewController---viewDidDisappear"); 39 } 40 41 - (void)dealloc 42 { 43 NSLog(@"FKSecondViewController---dealloc"); 44 }
3,开始执行,观察打印信息
3.1,程序启动完成时:
2015-04-08 22:52:25.314 01-测试Navigation[735:30225] FKOneViewController---loadView
2015-04-08 22:52:25.315 01-测试Navigation[735:30225] FKOneViewController---viewDidLoad
2015-04-08 22:52:25.316 01-测试Navigation[735:30225] FKOneViewController---viewWillAppear
2015-04-08 22:52:25.406 01-测试Navigation[735:30225] FKOneViewController---viewDidAppear
3.2,点击button跳转时:
2015-04-08 22:54:08.657 01-测试Navigation[735:30225] FKSecondViewController---loadView
2015-04-08 22:54:08.657 01-测试Navigation[735:30225] FKSecondViewController---viewDidLoad
2015-04-08 22:54:08.657 01-测试Navigation[735:30225] FKOneViewController---viewWillDisappear
2015-04-08 22:54:08.658 01-测试Navigation[735:30225] FKSecondViewController---viewWillAppear
2015-04-08 22:54:09.170 01-测试Navigation[735:30225] FKOneViewController---viewDidDisappear
2015-04-08 22:54:09.171 01-测试Navigation[735:30225] FKSecondViewController---viewDidAppear
3.3,点击返回箭头时:
2015-04-08 22:55:38.856 01-测试Navigation[735:30225] FKSecondViewController---viewWillDisappear
2015-04-08 22:55:38.856 01-测试Navigation[735:30225] FKOneViewController---viewWillAppear
2015-04-08 22:55:39.361 01-测试Navigation[735:30225] FKSecondViewController---viewDidDisappear
2015-04-08 22:55:39.361 01-测试Navigation[735:30225] FKOneViewController---viewDidAppear
2015-04-08 22:55:39.361 01-测试Navigation[735:30225] FKSecondViewController---dealloc
3.4,再次点击button时:
2015-04-08 22:57:03.755 01-测试Navigation[735:30225] FKSecondViewController---loadView
2015-04-08 22:57:03.756 01-测试Navigation[735:30225] FKSecondViewController---viewDidLoad
2015-04-08 22:57:03.756 01-测试Navigation[735:30225] FKOneViewController---viewWillDisappear
2015-04-08 22:57:03.756 01-测试Navigation[735:30225] FKSecondViewController---viewWillAppear
2015-04-08 22:57:04.263 01-测试Navigation[735:30225] FKOneViewController---viewDidDisappear
2015-04-08 22:57:04.264 01-测试Navigation[735:30225] FKSecondViewController---viewDidAppear