The life cycle and related functions of the IOS controller view

Source: Internet
Author: User

1.loadView 1.1 If the controller's Loadview method is overridden, the controller's view is created according to the description of the Loadview method

-(void) Loadview

{

Self.view = [[UIView alloc]init];

Self.view.backgroundColor = [Uicolor Redcolor];

}

1.2 If you do not rewrite the controller's Loadview method, then see if there is storyboard, if any, then according to the storyboard description to create a view

How to load Storyboard:

1> in Project--targets--maininterface designation storyboard

2> Code Loading

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];

Self.window.backgroundColor = [Uicolor Whitecolor];

Uistoryboard *mystoryboard = [Uistoryboard storyboardwithname:@ "Mystoryboard" bundle:nil];

Self.window.rootViewController = [Mystoryboard Instantiateinitialviewcontroller];

[Self.window makekeyandvisible];

return YES;

}

1.3 If there is no storyboard, then look at the initialization of the controller, there is no specified nibname, specified, press nibname corresponding xib CREATE view

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];

Self.window.backgroundColor = [Uicolor Whitecolor];

Self.window.rootViewController = [[Qkviewcontroller alloc]initwithnibname:@ "Myviewcontroller" bundle:nil];

[Self.window makekeyandvisible];

return YES;

}

1.4 If the nibname is not specified, assuming the controller name is Qkviewcontroller, then the program first looks for the name Qkview.xib, if found, then press Qkview.xib to create VIEW 1.5 if no qkview.xib is found, Then look for qkviewcontroller.xib, and if you find one, press Qkviewcontroller.xib to create the view

  Flowchart for the previous 5 steps:

2. The first 5 steps are actually doing loadview, after this step, call Viewdidload, will only be called once 3. Call Viewwillappear before the view is displayed, the function can be called more than 4. The view is displayed, Call VIEWDIDAPPEAR5. Call Viewwilldisapperar before the view disappears, the function can be called 6 more than once. Before and after the layout changes, call Viewwilllayoutsubviews\ ViewDidLayoutSubviews7. The controller also has three methods to note: viewwillunload\viewdidunload\didreceivememorywarning

When the program memory is not enough, the first to get the memory warning is uiapplication→window→window.rootviewcontroller→ .... (spread down one layer at a level).

When the controller receives a memory warning, it calls Viewwillunload\viewdidunload if it is determined to destroy the view.

This is how the controller determines if the view needs to be destroyed:

8. When the controller's view is destroyed, if it needs to be displayed again, the controller calls Loadview and starts from the Loadview of the first step.Summary: The life cycle of a controller is actually a closed loop

The life cycle and related functions of the IOS controller view

Related Article

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.