[IOS] ios-controller view creation and lifecycle

Source: Internet
Author: User

Reference to:

1. Creation of the Controller view

First, let's take a look at the flowchart created by the Controller view


Controller view load. jpeg


As we can see, there are two important methods Loadview and Viewdidload in the controller view loading process. Let's take a look at these two methods.

Loadview method Action: The Loadview method is used to create a view of the Uiviewcontroller. First determine if there is no specified storyboard or xib, if specified, will load the view of the controller they describe, if not specified, create an empty view. When to call: each time you access the Uiviewcontroller view, when view is nil, the Loadview method is called. Viewdidload function: In general, we will do the interface on the initialization, such as the view to add some sub-views and so on. When to call: The Viewdidload method will eventually be called whenever the view is created.

Second, there are some areas to be aware of during the view creation process.

1: The controller created through the storyboard, or through the xib created by the controller's view, the system will help us load the controller's view, the specific internal implementation can see Ios-uiwindow detailed, not in the Repeat 2:  Viewcontroller * VC = [[Viewcontroller alloc]init]; The underlying also calls-(Instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil method. (1). Determine if there is no specified nibname, if specified, will be loaded to load the specified Xib (2). If you do not specify, you will be judged if there is a controller class name with the same name of the Xib, there, will be loaded (3). Determine if there is a xib with the name of the controller class name, But the suffix without the controller xib, if any, will be loaded (4). If no xib describes the view of the controller, the xib is not loaded. A view with a color of Clearcolor is created.
2. The life cycle of the Controller view

Life cycle approach to Controller view

Loadview: Load Viewviewdidload:view loaded Viewwillappear: The controller's view will show Viewwilllayoutsubviews: The controller's view will be layout child controls Viewdidlayoutsubviews: Controller's view layout child controls Complete Viewdidappear: Controller view fully displays Viewwilldisappear: When the controller's view is about to disappear Viewdiddisappear: When the controller's view disappears completely

View life cycle method invocation Order

Viewdidload, Viewwillappear, Viewwilllayoutsubviews, Viewdidlayoutsubviews, Viewdidappear, Viewwilldisappear-Viewdiddisappear

3. Delay loading of the controller view

The controller's view is lazily loaded: Creating a controller does not necessarily create a view of the controller, and so on when it is loaded.

[IOS] ios-controller view creation and lifecycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.