iOS - UIViewController生命周期(storyboard/Xib/纯代码)(上)

简介: iOS - UIViewController生命周期(storyboard/Xib/纯代码)

一. 代码测试思路


创建三个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


相关文章
|
7月前
|
iOS开发
iOS开发解释 App 生命周期,包括各个阶段的调用顺序。
iOS开发解释 App 生命周期,包括各个阶段的调用顺序。
88 1
|
程序员 iOS开发
iOS App的生命周期
iOS App的生命周期
345 0
|
Swift iOS开发
IOS使用Swift加载Xib文件
IOS使用Swift加载Xib文件
333 0
|
iOS开发
IOS使用纯代码布局替换掉默认的storyboard
IOS使用纯代码布局替换掉默认的storyboard
110 0
|
存储 自然语言处理 API
iOS 多语言快捷设置Xib设置
iOS 多语言快捷设置Xib设置
iOS 多语言快捷设置Xib设置
|
iOS开发
iOS小技能:自动布局实现兄弟控件N等分且宽高比例是1:N(xib 上实现)
本文为 iOS视图约束专题的第三篇:xib上使用自动布局教程
188 0
|
Go iOS开发
iOS使用xib自定义uiview
iOS使用xib自定义uiview
372 0
iOS使用xib自定义uiview
|
数据可视化 程序员 iOS开发
iOS开发:用XIB拖控件关联时报错:“Could not insert new outlet connection…”解决方法
在iOS开发过程中,尤其是iOS开发初期,会遇到各种各样的错误,有些错误是开发者的不熟悉或者疏忽大意造成的,还有些是无厘头的错误,可以通过重启Xcode或者重启电脑就可解决。
285 0
iOS开发:用XIB拖控件关联时报错:“Could not insert new outlet connection…”解决方法
IOS_ViewController生命周期内各个函数的调用次序
IOS_ViewController生命周期内各个函数的调用次序
59 0
|
iOS开发
iOS生命周期篇
iOS生命周期篇
241 0