The relationship of iOS init, Loadview, Viewdidload, Viewdidunload

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
Viewcontroller calls this method when the view needs to be displayed and it is nil. Do not call the method directly.
If you maintain views manually, you must override this method.
If you use IB to maintain views, you must not override this method.
Loadview and IB build View

Viewdidload Method
override this method to further customize the view.
In iphone OS 3.0 and later, you should also rewrite Viewdidunload to release any indexes on the view.

The data model is called after viewdidload.

Viewdidunload Method
This method is called when the system memory is tight (note: Viewcontroller is not dealloc).
when memory is tight, didreceivememorywarning is the only way to free up unused memory before iphone OS 3.0, but OS 3.0 and later viewdidunload methods are a better way.
in this method, all Iboutlet (both property and instance variables) are set to nil (the System release view has already been removed).
in this method, other view-related objects are freed, other objects created at run time (but not system-required), objects created in viewdidload, cached data, and so on.
after the release object, set the object to nil (Iboutlet only need to set it to nil, and the system release view has already been removed).
It is generally assumed that viewdidunload is a viewdidload mirror, because Viewdidload is also re-executed when view is re-requested.
the objects that are viewdidunload in the release must be objects that are easily recreated (such as objects created in Viewdidload or other methods), and do not release user data or other objects that are difficult to re-create.

Dealloc Method
Viewdidunload and Dealloc methods are not associated, dealloc still do what it has to do.

So the process should look like this:
(loadview/nib file) to load view into memory-->viewdidload function to further initialize these view--> when memory is low, call the Viewdidunload function to release views
-When you need to use view, go back to the first step



The relationship of iOS init, Loadview, Viewdidload, Viewdidunload

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.