美文网首页程序员
iOS ViewController的生命周期

iOS ViewController的生命周期

作者: 陈盼同学 | 来源:发表于2019-04-24 15:49 被阅读0次
    #import "ViewController.h"
     
    @interface ViewController ()
    @property (nonatomic, strong) NSArray *array;
    @end
     
    @implementation ViewController
     
     
    /**
     *  view加载完毕调用
     */
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    }
     
    /**
     *  view即将显示到window上调用
     */
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }
     
    /**
     *  view显示完毕调用(已经显示到窗口上)
     */
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }
     
    /**
     *  view即将从window上移除(即将看不见)
     */
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }
     
    /**
     *  view从window上完全移除(完全看不见)
     */
    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }
     
    /**
     *  view即将销毁的时候调用
     */
    - (void)viewWillUnload
    {
        [super viewWillUnload];
    }
     
    /**
     *  view销毁完毕的时候调用
     */
    - (void)viewDidUnload
    {
        [super viewDidUnload];
         
        // 移除数据
        self.array = nil;
    
    }
     
    /**
     *  当接收到内存警告的时候
     */
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
     
    }
     
    @end
    

    执行顺序就是上面代码的顺序,从上往下

    loadView --> viewDidLoad --> viewWillAppear --> viewDidAppear --> viewWillDisappear --> viewDidDisappear --> viewWillUnload --> viewDidUnload

    相关文章

      网友评论

        本文标题:iOS ViewController的生命周期

        本文链接:https://www.haomeiwen.com/subject/djyggqtx.html