The timing of each method call-init, Viewdidload, Viewwillappear, Viewdidappear, Viewwilldisappear, viewdiddisappear

Source: Internet
Author: User

Init: Method

Instantiate the necessary objects in the Init method (follow the lazyload idea)

Initialize the Viewcontroller itself in the Init method


Loadview: Method

This is when the nib View page is not being used, and the subclass will create its own custom view layer. Must not be called directly.

If you maintain views manually, you must override this method with overloading.

Viewcontroller calls this method when the view needs to be displayed and it is nil.

Loadview and IB Build view

You implement the Loadview method in the controller, then you may be called by the memory management control at some point when the application is running. If the device is low on memory, the view controller receives a didreceivememorywarning message. The default implementation is to check whether the current controller's view is in use. If its view is not inside the view hierarchy currently in use and your controller implements the Loadview method, the view will be release and the Loadview method will be re-used to create a new view.

Viewdidload: Method

Called after the view has been loaded:

If the view loader is created in code, he will be called after the Loadview method.

If it is output from the nib View page, he will be called after the view has been set up.

Overloads override this method to further customize the view

In iphone OS 3.0 and later versions, you should also overload the rewrite Viewdidunload to release any indexes on the view

Call data Model after Viewdidload


Viewwillappear: Method
Called when the view was about to made visible. Default does nothing
Called when the view is about to be visible. No action is taken by default


Viewdidappear:
Called when the view had been fully transitioned onto the screen. Default does nothing
Called when the view has completely transitioned to the screen


Viewwilldisappear:
Called when the view is dismissed, covered or otherwise hidden. Default does nothing
The view is dismissed when called, overwritten, or otherwise hidden. No action is taken by default


Viewdiddisappear:
Called after the view is dismissed, covered or otherwise hidden. Default does nothing
The view is dismissed after it is called, overwritten, or otherwise hidden. No action is taken by default


The following is a summary of a friend quoted online, Link:http://blog.csdn.net/weasleyqi/article/details/8090373

Execution order:

From the log view of the program:

2012-10-19 15:51:44.811inhyron[483:b903] Init

2012-10-19 15:51:54.081inhyron[483:b903] Viewdidload

2012-10-19 15:51:54.082inhyron[483:b903] Viewvillappear

2012-10-19 15:51:54.084 inhyron[483:b903] Viewdidappear

Obviously, Init is executed first, then viewdidload is executed , then viewwillappear is finally viewdidappear, so the view is created, When the view disappears or is overwritten:

2012-10-19 15:54:14.557inhyron[483:b903] Viewwilldisappear

2012-10-19 15:54:14.558inhyron[483:b903] Viewdiddisappear

This way the view disappears when the memory warning is simulated:

2012-10-19 15:55:14.333inhyron[483:b903] Received simulated memory warning.

2012-10-19 15:55:14.334inhyron[483:b903] Viewwillunload

2012-10-19 15:55:14.335 Inhyron[483:b903]viewdidunload

As can be seen from log, when the view control object receives a memory warning, the program executes Viewwillunload and finally executes viewdidunload.

In this way, a set of processes is completed.

That's the guy's summary, Link: http://blog.csdn.net/weasleyqi/article/details/8090373

In fact, when view a switches to view B, the real process is not running down the process,

Not a view: 1,viewwilldisappear 2,viewdiddisappear, then B view: 3,viewdidload 4,viewvillappear 5, Viewdidappear like this.

The correct sequence of processes should be:

1,b View viewdidload

2,a View viewwilldisappear

viewvillappear

4,a view   Viewdiddisappear

5,b View viewdidappear


Screen jumps the time of each method call-init, Viewdidload, Viewwillappear, Viewdidappear, Viewwilldisappear, viewdiddisappear

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.