zoukankan      html  css  js  c++  java
  • 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__);
    
    }

    打印结果:

  • 相关阅读:
    C#
    C#
    ssh学习笔记
    (已解决)Could not open '/var/lib/nova/mnt/*/volume-*': Permission denied
    RPCVersionCapError: Requested message version, 4.17 is incompatible. It needs to be equal in major version and less than or equal in minor version as the specified version cap 4.11.
    如何在linux下安装idea
    The system has no LUN copy license
    调整mysql数据库最大连接数
    mysql数据库编码问题
    cinder支持nfs快照
  • 原文地址:https://www.cnblogs.com/vkSwift/p/13983278.html
Copyright © 2011-2022 走看看