"IOS" Init,loadview,viewdidload load relationship

Source: Internet
Author: User

First, Loadview

Never call this function actively. The view controller calls this function when the property of the view is requested and the current view value is nil. If you create a view manually, you should reload the function. If you create a view with IB and initialize the view controller, that means you use the Initwithnibname:bundle: method, and you should not overload the Loadview function.

The default implementation of this method is to look for information about the available nib files, load the nib file based on this information, and if there is no information about the nib file, the default implementation creates a blank UIView object and then makes the object the controller's main view.

So, when you overload this function, you should do the same. and assign the View property (the view of your create must be a unique instance and not be shared by any other controller), and the function you overload should not call super.

If you want to make further initialization of your views, you should do it in the Viewdidload function. In iOS 3.0 and later, you should reload the Viewdidunload function to free any references to the view or content inside it (sub-view, and so on).

This online information is not comprehensive, especially the blue word part.

Second, Viewdidload

This function is called after the controller has loaded the relevant views, regardless of whether the views are stored in the nib file or generated in the Loadview function. In most cases, it is the follow-up work of nib files.

The description of this function on the Internet is completely wrong.

Third, Viewdidunload

This function is the opposite function of viewdidload. This function is called by the Controller () when the program memory is missing. Since the controller usually holds references to objects related to the view (which is typically the view's child view) or to other objects created by the runtime, the So you have to use this function to discard the ownership of these objects for memory recycling. But do not release data that is difficult to reconstruct (do not release viewin this function).

Usually the controller saves a reference to the views created by the nib file, but it may also hold a reference to the object that the Loadview function creates. The perfect method is to use the Synthesizer method:

Self.mycertainview = nil;

The synth will release the view, and if you don't use the property, you have to explicitly release the view yourself.

The description of the function on the net vague, looked at equals not to see.

Also: If the controller stores references to other object and view, you also have to release the memory in the Dealloc method. For ios2.x, you must also set these references to nil before calling the Super Dealloc method.

Iv. Conclusion

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

---------------------------------------------------------------------------------------

Add a little bit of your own problems:

1. Loadview,viewdidload is called only when it is called to self.view and view = nil.

2. Note the loading order of the initialization content. If you are loading manually, add the view you created when you loadview. Viewdidload only follow up on previously loaded view, and the newly created content after Viewdidload can be released when memory is low (this problem needs to be tested).

"IOS" Init,loadview,viewdidload load relationship

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.