• UIViewcontroller生命周期方法


    UIViewcontroller生命周期方法

    // 非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];
    
        
    
        UIButton *btn = [[UIButton alloc]init];
    
        btn.backgroundColor = [UIColor systemBlueColor];
    
        btn.tag = 100;
    
        [self.view addSubview:btn];
    
    }
    
     
    
    //视图控制器中的视图加载完成,viewController自带的view加载完成
    
    - (void)viewDidLoad {
    
        NSLog(@"%s", __FUNCTION__);
    
        [super viewDidLoad];
    
    //     self.view = nil ;
    
     
    
    }
    
    - (void)updateViewConstraints{
    
        
    
        [super updateViewConstraints];
    
        
    
        UIButton * btn = (UIButton *)[self.view viewWithTag:100];
    
        
    
        btn.frame = CGRectMake(CGRectGetMidX(self.view.bounds) - 50, CGRectGetMidY(self.view.bounds) - 15, 100, 30);
    
        
    
        
    
        NSLog(@"%s",__FUNCTION__);
    
        
    
    }
    
     
    
    //视图将要出现
    
    - (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__);
    
    }

    打印结果:

  • 相关阅读:
    docker安装
    [golang grpc] 框架介绍
    docker介绍
    Visual Studio Code常用设置
    eclipse常用设置
    [golang note] 网络编程
    [golang note] 工程组织
    [golang note] 协程通信
    [golang note] 协程基础
    [golang note] 接口使用
  • 原文地址:https://www.cnblogs.com/vkSwift/p/13983278.html
Copyright © 2020-2023  润新知