iOS[Swift] -- Life cycle of UIViewContorller

uiviewcontroller_lifecycle

平时在讲ViewController的生命周期时,我们只大多只关注以下六个方法:

  • viewDidLoad
    *viewWillAppear
  • viewDidAppear
  • viewWillDisappear
  • viewDidDisappear
  • viewDidUnload

其实ViewController的生命周期如下:

  • loadView[1]
  • viewDidLoad[1]
  • viewWillAppear
  • viewWillLayoutSubviews [2]

    Called to notify the view controller that its view is about to layout its subviews.

  • viewDidLayoutSubviews[2]

Called to notify the view controller that its view has just laid out its subviews.

  • viewDidAppear
  • viewWillLayoutSubviews
  • viewDidLayoutSubviews
  • viewWillDisappear
  • viewDidDisappear
  • viewDidUnload

  1. If you manually nil out your view during didReceiveMemoryWarning, loadView and viewDidLoad will be called again. That is, by default loadView and viewDidLoad only gets called once per view controller instance.

  2. May be called an additional 0 or more times .viewWillLayoutSubviews and viewDidLayoutSubviews will also be called at other times when subviews of the main view are loaded, for example when cells of a table view or collection view are loaded.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容