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


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

热门文章

最新文章

  • 1
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    23
  • 2
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
    21
  • 3
    uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
    141
  • 4
    【05】2025年1月首发完整版-篇幅较长-苹果app如何上架到app store完整流程·不借助第三方上架工具的情况下无需花钱但需仔细学习-优雅草央千澈详解关于APP签名以及分发-们最关心的一篇来了-IOS上架app
    222
  • 5
    app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
    87
  • 6
    深入探索iOS开发中的SwiftUI框架
    143
  • 7
    ios样式开关按钮jQuery插件
    58
  • 8
    Android与iOS生态差异深度剖析:技术架构、开发体验与市场影响####
    74
  • 9
    深入探索iOS与Android操作系统的安全性差异
    102
  • 10
    安卓与iOS开发中的跨平台策略:一次编码,多平台部署
    173