一. 代码测试思路
创建三个UIViewController,第一个storyboard创建,第二个Xib创建,第三个纯代码创建,分别为:BoardInitViewController
,XibInitViewController
,CodeInitViewController
, 这个三个vc通过导航模式交互,在vc中把所有跟初始化相关的放大实现并打印
BoardInitViewController.m
// // BoardInitViewController.m // ControllerLifeCycle // // Created by Ternence on 2021/4/29. // #import "BoardInitViewController.h" #import "CodeInitViewController.h" @interface BoardInitViewController () @end @implementation BoardInitViewController + (void)load { [super load]; NSLog(@"boardVC------%s", __func__); } + (void)initialize { [super initialize]; NSLog(@"boardVC------%s", __func__); } + (instancetype)alloc { NSLog(@"boardVC------%s", __func__); return [super alloc]; } - (nullable instancetype)initWithCoder:(NSCoder *)coder { NSLog(@"boardVC------%s", __func__); return [super initWithCoder:coder]; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { NSLog(@"boardVC------%s", __func__); return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; } - (instancetype)init { NSLog(@"boardVC------%s", __func__); return [super init]; } - (void)loadView { [super loadView]; NSLog(@"boardVC------%s", __func__); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"boardVC------%s", __func__); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"boardVC------%s", __func__); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"boardVC------%s", __func__); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; NSLog(@"boardVC------%s", __func__); } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"boardVC------%s", __func__); self.view.backgroundColor = [UIColor lightTextColor]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; NSLog(@"boardVC------%s", __func__); } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; NSLog(@"boardVC------%s", __func__); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; NSLog(@"boardVC------%s", __func__); } - (void)dealloc { NSLog(@"boardVC------%s", __func__); } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; CodeInitViewController *vc = [[ CodeInitViewController alloc]init]; [self.navigationController pushViewController:vc animated:YES]; } @end
XibInitViewController.m
// // XibInitViewController.m // ControllerLifeCycle // // Created by Ternence on 2021/4/29. // #import "XibInitViewController.h" @interface XibInitViewController () @end @implementation XibInitViewController + (void)load { [super load]; NSLog(@"XibVC------%s", __func__); } + (void)initialize { [super initialize]; NSLog(@"XibVC------%s", __func__); } + (instancetype)alloc { NSLog(@"XibVC------%s", __func__); return [super alloc]; } - (nullable instancetype)initWithCoder:(NSCoder *)coder { NSLog(@"XibVC------%s", __func__); return [super initWithCoder:coder]; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { NSLog(@"XibVC------%s", __func__); return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; } - (instancetype)init { NSLog(@"XibVC------%s", __func__); return [super init]; } - (void)loadView { [super loadView]; NSLog(@"XibVC------%s", __func__); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"XibVC------%s", __func__); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"XibVC------%s", __func__); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"XibVC------%s", __func__); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; NSLog(@"XibVC------%s", __func__); } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"XibVC------%s", __func__); self.view.backgroundColor = [UIColor blueColor]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; NSLog(@"XibVC------%s", __func__); } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; NSLog(@"XibVC------%s", __func__); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; NSLog(@"XibVC------%s", __func__); } - (void)dealloc { NSLog(@"XibVC------%s", __func__); } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; } @end