Methods of View Controller Lifecycle

Source: Internet
Author: User
-(Void) awakefromnib; when this method is used, the outlet is not connected yet. The View Controller was not completely created when it was just created from the storyboard, however, there may be some things to be done in this method, such as splitviewdelegate, which needs to be done very early.

-(Void) viewdidload;

When this is used, viewcontroller is completely ready and the outlet is connected. But it is not displayed on the screen. This method can contain a lot of set code. When this method is executed, the view bounds does not exist. Load first, then appear. Ha-(void) viewwillappear :( bool) animated; bounds already exists when this method is called. Your view can only be loaded once, but it can be appear or disappear many times. So the unchanged things are placed in viewdidload. Ry-related data is stored in viewwillappear. This is very important for project optimization... Haha is like a view on the top layer. to rotate an iPad or something, you need to change the size of the view on the top layer. When the lifecycle of a view controller is here, you can adjust the arrangement or geometric properties of the view at the last moment. Here we also set some lazy execution for performance. For example, You need to press a button to display a view or something. This setting is costly. It is better to open another thread in viewwillappear to run a long time-consuming task, and then put a tiny spinning wheel in the view. -(Void) viewwilldisappear :( bool) animated {[Super viewwilldisappear: animated]; [self rememberscrollposition]; [self savedatatopermanentstore];} This method is of course about to disappear. Remember the current running status when you want to disappear. So remember the position of scroll. However, do not write too many things in this method. The app will crash. Open another thread to handle any UI changes, or write the changes to the hard disk if the resources are not waste. -(Void) viewdidappear :( bool) animated;-(void) viewdiddisappear :( bool) animated; Will did version. Used after the view is displayed. -(Void) viewwilllayoutsubviews; did version:-(void) viewdidlayoutsubviews; this method is called before the subview is triggered by frame changes. For example, after Autorotation, the layout changes, in this case, you can set the layout of the subview. More ratation methods:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)anOrientation duration:(NSTimeInterval)seconds;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOriention)orient duration:(NSTimeInterval)seconds;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)anOrientation;
@property UIInterfaceOrientation interfaceOrientation;
 
A low memory condition in the lifecycle:
- (void)viewDidUnload
{
   self.faceView = nil;
}
When the memory is low, the system will unmount your view and clear the view of your controller from the memory, that is, stop all pointers directed by strong.
However, the corresponding viewcontroller will not be cleared from the heap.
However, you still need to set all other outlet pointers to nil, because other views may point to this type of strong pointer, so it is not the same. Therefore, we need to develop a good habit and set the outlet pointer to nil.

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.