美文网首页
UIViewController的生命周期

UIViewController的生命周期

作者: 彭小先生 | 来源:发表于2018-05-02 18:07 被阅读0次

    程序加载时的输出顺序

    2018-05-02 17:38:26.827444+0800 生命周期[24679:330724] -[AppDelegate application:didFinishLaunchingWithOptions:]
    2018-05-02 17:38:26.828856+0800 生命周期[24679:330724] loadView
    2018-05-02 17:38:26.829402+0800 生命周期[24679:330724] viewDidLoad
    2018-05-02 17:38:26.829679+0800 生命周期[24679:330724] viewWillAppear
    2018-05-02 17:38:26.835132+0800 生命周期[24679:330724] viewDidAppear
    2018-05-02 17:38:26.836846+0800 生命周期[24679:330724] -[AppDelegate applicationDidBecomeActive:]
    

    程序进入后台在进入时

    2018-05-02 17:43:15.783062+0800 生命周期[24679:330724] -[AppDelegate applicationWillResignActive:]
    2018-05-02 17:43:20.588755+0800 生命周期[24679:330724] -[AppDelegate applicationWillEnterForeground:]
    2018-05-02 17:43:20.869057+0800 生命周期[24679:330724] -[AppDelegate applicationDidBecomeActive:]
    

    页面跳转时

    2018-05-02 17:51:25.280818+0800 生命周期[24767:338063] viewWillDisappear
    2018-05-02 17:51:25.925970+0800 生命周期[24767:338063] viewDidDisappear
    

    补充:跳转的方式不同两个页面view的调用顺序也不一样,这里给一下结果

    当push到secondVC后并返回

    2018-05-02 17:51:25.280818+0800 生命周期[24767:338063] viewWillDisappear
    2018-05-02 17:51:25.925970+0800 生命周期[24767:338063] viewDidDisappear
    2018-05-02 17:53:50.210056+0800 生命周期[24767:338063] second viewWillDisappear
    2018-05-02 17:53:50.210353+0800 生命周期[24767:338063] viewWillAppear
    2018-05-02 17:53:50.716948+0800 生命周期[24767:338063] second viewDidDisappear
    2018-05-02 17:53:50.717192+0800 生命周期[24767:338063] viewDidAppear
    //secondVC将要消失时 viewcontroller才即将出现。second完全消失时,vc才完全出现
    

    当present到secondVC后并返回

    2018-05-02 17:59:11.146236+0800 生命周期[24820:342564] viewWillDisappear
    2018-05-02 17:59:11.666224+0800 生命周期[24820:342564] viewDidDisappear
    2018-05-02 17:59:13.722392+0800 生命周期[24820:342564] second viewWillDisappear
    2018-05-02 17:59:13.722639+0800 生命周期[24820:342564] viewWillAppear
    2018-05-02 17:59:14.229585+0800 生命周期[24820:342564] viewDidAppear
    2018-05-02 17:59:14.229797+0800 生命周期[24820:342564] second viewDidDisappear
    //与push不同:second执行dismiss后本身是即将消失状态,当vc即将出现到出现后second才完全消失。
    

    相关文章

      网友评论

          本文标题:UIViewController的生命周期

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