zoukankan      html  css  js  c++  java
  • (转载)UIViewController lifecycle

    The UIViewController object is one of the most used objects available in the iOS SDK. It’s important to understand the lifecycle events of this controller and know how we should use them. We are going to focus on the events used toload a view.

    > Lifecycle events order

    1. - (void)loadView
    2. - (void)viewDidLoad
    3. - (void)viewWillAppear
    4. - (void)viewWillLayoutSubviews
    5. - (void)viewDidLayoutSubviews
    6. - (void)viewDidAppear

    > How can we use them?

    - (void)loadView — Creates the view that the controller manages.

    It’s only called when the view controller is created and only when done programatically. You can override this method in order to create your views manually.

    - (void)viewDidLoad — Called after the controller’s view is loaded into memory.

    It’s only called when the view is created. Keep in mind that in this lifecycle step the view bounds are not final. Good place to init and setup objects used in the viewController.

    - (void)viewWillAppear:(BOOL)animated — Notifies the view controller that its view is about to be added to a view hierarchy.

    It’s called whenever the view is presented on the screen. In this step the view has bounds defined but the orientation is not applied. This event is called every time the view appears so don’t add code here which should be executed just one time (or manage it correctly).

    - (void)viewWillLayoutSubviews — Called to notify the view controller that its view is about to layout its subviews.

    This method is called every time the frame changes like for example when rotate or it’s marked as needing layout. It’s the first step where the view bounds are final. If you are not using autoresizing masks or constraints and the view size changes you probably want to update the subviews here.

    - (void)viewDidLayoutSubviews — Called to notify the view controller that its view has just laid out its subviews.

    Make additional changes here after the view lays out its subviews.

    - (void)viewDidAppear:(BOOL)animated — Notifies the view controller that its view was added to a view hierarchy.

    Good place to perform additional tasks associated with presenting the viewlike animations. This method is executed after the animation displaying the view finishes so in this step the view is already visible for the user. In some cases can be a good place to load data from core data and present it in the view or to start requesting data from a server.

     

    转载自:https://medium.com/@SergiGracia/ios-uiviewcontroller-lifecycle-261e3e2f6133

  • 相关阅读:
    rzchecktree用作类别权限的问题
    VirtualStringTree 动态建树/Checktree
    一键处理打印机因任务不能取消,无法接着打印
    Delphi从Internet下载文件
    仿迅雷客户端的浏览器自定义协议的小程序
    用最少的代码为你的窗体实现剪贴板操作
    delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标
    datasnap 上传/下载大文件(本Demo以图传片文件为例)
    dephi中用idhttp提交cookie
    delphi2010 向另一个窗口发送鼠标点击事件
  • 原文地址:https://www.cnblogs.com/scaptain/p/4118654.html
Copyright © 2011-2022 走看看