美文网首页
ViewController生命周期方法执行顺序

ViewController生命周期方法执行顺序

作者: 只敲代码不偷桃 | 来源:发表于2016-04-08 17:00 被阅读112次
    warning 生命周期的方法调用顺序是从1到10
    // 1
    - (instancetype)init
    {
        self = [super init];
        if (self) {
            NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
        }
        return self;
    }
    // 2
    - (void)loadView
    {
        [super loadView];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 3
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 4
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 5
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 6
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 7
    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }
    // 8
    - (void)viewWillUnload
    {
        [super viewWillUnload];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 9
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    // 10
    - (void)dealloc
    {
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    

    initialize和load的区别

    Apple的文档很清楚地说明了initialize和load的区别在于:load是只要类所在文件被引用就会被调用,而initialize是在类或者其子类的第一个方法被调用前调用。所以如果类没有被引用进项目,就不会有load调用;但即使类文件被引用进来,但是没有使用,那么initialize也不会被调用。


    ViewController生命周期

    相关文章

      网友评论

          本文标题:ViewController生命周期方法执行顺序

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