The life cycle of the "IOS" Uiviewcontroller

Source: Internet
Author: User

2 loops present in the Uiviewcontroller:

in Uiviewcontroller, view has two loops: load loop and the Unloading loops .


Load loop
1 "
program request controller view.

2 " If the view is in memory, it is loaded directly. Conversely, if it does not exist, Uiviewcontroller calls the Loadview method .

3The Loadview method performs the following actions:

If you overload this method, you must create the necessary view and pass a non-nil value to the Uiviewcontroller view property.

If you do not overload this function, Uiviewcontroller will use Uiviewcontroller's Nibname and Nibbundle properties to attempt to load the view from the nib file by default. If the nib file is not found, it tries to find a nib file that matches the Uiviewcontroller class name.

If there is no nib file available, then it creates an empty uiview as its view.

4 " Uiviewcontroller calls Viewdidload to perform some load-time tasks.


Unloading loops
1 "The program receives a memory warning. 2 "Each Uiviewcontroller calls didreceivememorywarning, and the view is safely freed by default. 3 " if Uiviewcontroller releases its view, it will call Viewdidunload. This method can be overloaded to perform additional cleanup work.
the life cycle of Uiviewcontroller:When a view controller is created and displayed on the screen. Order of execution of code

1, alloc                                   Create objects, allocate space
2, init (INI Twithnibname) Initialize object, initialize Data
3, Loadview                       &NBSP ;   Loading views from the nib, usually this step does not need to interfere. Unless you are not using the Xib file to create the View
4, viewdidload                   loading complete, You can customize the data and dynamically create additional controls
5, viewwillappear               The view will appear before the screen, and this view will be displayed on the screen immediately.
6, Viewdidappear               View on-screen rendering complete

When a view is removed from the screen and the execution order is destroyed, the order is almost the opposite of the above.
1. Viewwilldisappear view will be removed from the screen before execution
2, Viewdiddisappear view has been removed from the screen, the user can not see this view
3. Dealloc view is destroyed, you need to release the objects you created in Init and viewdidload

About Viewdidunload: In the event of a memory warning, if this view is not the view being displayed on the current screen, Viewdidunload will be executed and all child views of this view will be destroyed to free up memory, when developers need to manually viewload, The objects created in the Viewdidload free memory. Because when the view is displayed again on the screen, Viewload and viewdidload are called again to construct the view again.


Reference: http://blog.csdn.net/huifeidexin_1/article/details/7566226

http://blog.csdn.net/teamlet/article/details/8579129


xn4545945 Collection and collation: http://blog.csdn.net/xn4545945


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.