(转载)UIViewController lifecycle
2014-11-24 14:45
495 查看
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
- (void)loadView
- (void)viewDidLoad
- (void)viewWillAppear
- (void)viewWillLayoutSubviews
- (void)viewDidLayoutSubviews
- (void)viewDidAppear
> How can we use them?
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.
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.
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).
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.
Make additional changes here after the view lays out its subviews.
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
> Lifecycle events order
- (void)loadView
- (void)viewDidLoad
- (void)viewWillAppear
- (void)viewWillLayoutSubviews
- (void)viewDidLayoutSubviews
- (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
相关文章推荐
- UIViewController LifeCycle 笔记
- UIViewController of lifecycle
- PowerEdge服务器Lifecycle Controller简介
- 【转载】tomcat启动时报错:org.apache.catalina.core.AprLifecycleListener init
- 转载---React Component Lifecycle
- iOS应用开发视频教程笔记(八)Controller Lifecycle & ImageScrollWebViews
- 转载:Understanding WPF Application Lifecycle
- CS193p Lecture 5 - View Controller Lifecycle
- iOS 笔记三: UITextView和视图控制器生命周期(View Controller LifeCycle)
- 视图控制器生命周期中各个重要的方法(Swift) (Important Methods during the Lifecycle of a View Controller)
- iOS 7应用开发公开课笔记 L5:View Controller Lifecycle
- Girl_iOS100天学iOS的第二天(App lifecycle&viewController lifecycle)
- 视图控制器生命周期(ViewController Lifecycle)
- org.apache.catalina.LifecycleException: A child container failed during(转载)
- PowerEdge服务器生命周期控制器:Lifecycle Controller
- iOS 7 ViewController Lifecycle
- 【Java多线程】之四:Life Cycle of Thread
- Fragment life cycle
- Eclipse 报Plugin execution not covered by lifecycle configuration
- tomcat run的时候报LifecycleExecutionException或者A child container failed during start错误