A new method of Uiviewcontroller in IOS5

Source: Internet
Author: User

    1. A new method of Uiviewcontroller in IOS5
Objective

Video of the WWDC2011 conference in Apple
Session 101-what ' s New in Cocoa and
"Session 102-implementing Uiviewcontroller Containment" describes Apple's new addition to the Uiviewcontroller 5 method and a property in IOS5:

Method

Removefromparentviewcontroller:


Didmovetoparentviewcontroller:
Property
@property (nonatomic,nsarray *childviewcontrollers
The original question

These new methods and properties are used to improve our way of programming. So let's take a look at some of the previous potential problems with the use of Uiviewcontroller and recognize the problem, so that we can understand the meaning of Apple's change.

In the past, a Uiviewcontroller view might have a lot of small sub-view. These sub-view are often covered at the end, and we add a lot of sub-view with Addsubview in the outermost Viewcontroller Viewdidload method. Most of these sub-view will not always be on the interface, only in some cases will appear, such as the login failed prompt view, upload attachment successful hint view, network failure prompt view and so on. But while these are rarely seen, we often keep them in memory. In addition, when a memory warning is received, we can only manually remove these view from Super view.

Change

Apple's new API adds the Addchildviewcontroller method and wants us to call the [self Addchildviewcontroller:child] method when using Addsubview, which corresponds to the VI of Sub view Ewcontroller is also added to the current Viewcontroller management. For those who currently do not need to display the Subview, only through the Addchildviewcontroller Subviewcontroller add in. Call the TransitionFromViewController:toViewController:duration:options:animations:completion method when it needs to be displayed.

In addition, when the memory Warning of the system is received, the system will automatically unload out the subview that are not currently displayed to save RAM.

Resources

Here's a nice article about this. A sample code is introduced to demonstrate the use of the new API.

I also modified the code slightly to add the view load, unload, appear, disappear event log, and log when I received the Memory Warning. The code on GitHub, the address is here, interested students can download their own to see the source code.

The

can see that the view is not load when not in use, and when there is Memory Warning, the view that is not currently displayed is automatically unload out. Therefore, the new method can effectively save memory, and can easily handle the resource recovery when the memory is low. Run Log as follows:

[7397:f803]-[firstviewcontroller willmovetoparentviewcontroller:][7397:f803]-[secondviewcontroller WILLMOVETOPARENTVIEWCONTROLLER:][7397:F803]-[thirdviewcontroller willmovetoparentviewcontroller:][7397:f803]-[ Thirdviewcontroller viewdidload][7397:f803]-[thirdviewcontroller viewwillappear:][7397:f803] [ Thirdviewcontroller viewdidappear:][7397:f803] Birthday reminder [7397:f803]-[secondviewcontroller viewDidLoad][7397:f803]-[ Thirdviewcontroller viewwilldisappear:][7397:f803]-[secondviewcontroller viewwillappear:][7397:f803] [ Secondviewcontroller viewdidappear:][7397:f803]-[thirdviewcontroller viewdiddisappear:][7397:f803] message and reply [7397: F803]-[firstviewcontroller viewdidload][7397:f803]-[secondviewcontroller viewwilldisappear:][7397:f803]-[ Firstviewcontroller viewwillappear:][7397:f803]-[firstviewcontroller viewdidappear:][7397:f803] [ Secondviewcontroller viewdiddisappear:][7397:f803] Received memory warning. [7397:f803]-[secondviewcontroller viewdidunload][7397:f803]-[thirdviewcontroller Viewdidunload] 

A new method of Uiviewcontroller in IOS5

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.