🔥UIViewController的生命周期
Posted 1-434
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了🔥UIViewController的生命周期相关的知识,希望对你有一定的参考价值。
UIViewController 的 生命周期
#pragma mark --- life circle // 非storyBoard(xib或非xib)都走这个方法 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { NSLog(@"%s", __FUNCTION__); if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { } return self; } // 如果连接了串联图storyBoard 走这个方法 - (instancetype)initWithCoder:(NSCoder *)aDecoder { NSLog(@"%s", __FUNCTION__); if (self = [super initWithCoder:aDecoder]) { } return self; } // xib 加载 完成 - (void)awakeFromNib { [super awakeFromNib]; NSLog(@"%s", __FUNCTION__); } // 加载视图(默认从nib) - (void)loadView { NSLog(@"%s", __FUNCTION__); self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.view.backgroundColor = [UIColor redColor]; } //视图控制器中的视图加载完成,viewController自带的view加载完成 - (void)viewDidLoad { NSLog(@"%s", __FUNCTION__); [super viewDidLoad]; } //视图将要出现 - (void)viewWillAppear:(BOOL)animated { NSLog(@"%s", __FUNCTION__); [super viewWillAppear:animated]; } // view 即将布局其 Subviews - (void)viewWillLayoutSubviews { NSLog(@"%s", __FUNCTION__); [super viewWillLayoutSubviews]; } // view 已经布局其 Subviews - (void)viewDidLayoutSubviews { NSLog(@"%s", __FUNCTION__); [super viewDidLayoutSubviews]; } //视图已经出现 - (void)viewDidAppear:(BOOL)animated { NSLog(@"%s", __FUNCTION__); [super viewDidAppear:animated]; } //视图将要消失 - (void)viewWillDisappear:(BOOL)animated { NSLog(@"%s", __FUNCTION__); [super viewWillDisappear:animated]; } //视图已经消失 - (void)viewDidDisappear:(BOOL)animated { NSLog(@"%s", __FUNCTION__); [super viewDidDisappear:animated]; } //出现内存警告 //模拟内存警告:点击模拟器->hardware-> Simulate Memory Warning - (void)didReceiveMemoryWarning { NSLog(@"%s", __FUNCTION__); [super didReceiveMemoryWarning]; } // 视图被销毁 - (void)dealloc { NSLog(@"%s", __FUNCTION__); } ** 查看 打印 结果 ** 2017-03-01 18:03:41.577 ViewControllerLifeCircle[32254:401790] -[ViewController initWithCoder:] 2017-03-01 18:03:41.579 ViewControllerLifeCircle[32254:401790] -[ViewController awakeFromNib] 2017-03-01 18:03:41.581 ViewControllerLifeCircle[32254:401790] -[ViewController loadView] 2017-03-01 18:03:46.485 ViewControllerLifeCircle[32254:401790] -[ViewController viewDidLoad] 2017-03-01 18:03:46.486 ViewControllerLifeCircle[32254:401790] -[ViewController viewWillAppear:] 2017-03-01 18:03:46.487 ViewControllerLifeCircle[32254:401790] -[ViewController viewWillLayoutSubviews] 2017-03-01 18:03:46.488 ViewControllerLifeCircle[32254:401790] -[ViewController viewDidLayoutSubviews] 2017-03-01 18:03:46.490 ViewControllerLifeCircle[32254:401790] -[ViewController viewDidAppear:] 2017-03-01 19:03:13.308 ViewControllerLifeCircle[32611:427962] -[ViewController viewWillDisappear:] 2017-03-01 19:03:14.683 ViewControllerLifeCircle[32611:427962] -[ViewController viewDidDisappear:] 2017-03-01 19:03:14.683 ViewControllerLifeCircle[32611:427962] -[ViewController dealloc] 2017-03-01 19:12:05.927 ViewControllerLifeCircle[32611:427962] -[ViewController didReceiveMemoryWarning]
T
以上是关于🔥UIViewController的生命周期的主要内容,如果未能解决你的问题,请参考以下文章