Methods triggered during view loading (loadView/viewDidLoad/didReceiveMemoryWarning) and loadviewviewdidload

Source: Internet
Author: User

Methods triggered during view loading (loadView/viewDidLoad/didReceiveMemoryWarning) and loadviewviewdidload

1. loadView

This is how the View Controller loads the Root View;

If you need to use a custom view as the root view, you do not need to call the implementation of this method by the parent class ([super loadView]); directly use the custom view through self. view is defined as the Root view of the view Controller;

Simple response events in a custom view should also be processed by the View Controller, written in this method;

2. viewDIdLoad

This method is triggered after the View Controller's Root View is loaded. (This method is called immediately after loadView is called );

The implementation of this method by calling the parent class;

This method can be used to set the root view, such as the background color;

3. viewWillAppear :( BOOL) animated; // triggered when the View Controller's root view is to be displayed;

4. viewDidAppear :( BOOL) animated; // triggered when the View Controller's Root View is displayed;

5. viewWillDisappear :( BOOL) animated; // triggered when the Root View of the View Controller is about to disappear;

6. viewDidDisappear :( BOOL) animated; // triggered when the Root View of the View Controller disappears;

7. didReceiveMemoryWarning; // triggered when a memory warning is received. In this case, you need to release unused resources and rebuild objects;

1-(void) didReceiveMemoryWarning {2 [super didReceiveMemoryWarning]; 3 if ([self isViewLoaded] &! Self. view. window) {4 self. view = nil; 5} 6} 7 // [self isViewLoaded] Check whether the view has been loaded 8 // self. view. is the Root View displayed on the window?

 

# Pragma mark -- methods related to screen Rotation

8. Set whether the current interface changes when the device is rotated. rotation is supported.

-(BOOL) shouldAutorotate {

Return YES;

}

9. Set the orientation of rotation supported by the current interface. It must depend on the orientation supported by the current application;

-(NSUInteger) supportedInterfaceOrientations {

Return UIInterfaceOrientationMaskAll; // all directions are supported.

}

10. triggered when the screen is rotated, valid after iOS8

-(Void) viewWillTransitionToSize :( CGSize) size withTransitionCoordinator :( id <UIViewControllerTransitionCoordinator>) coordinator {

// Size indicates the size of the screen after rotation;

NSLog (@ "% @", NSStringFromCGSize (size); // output the screen size at this time;

}

 

Methods for calling the parent class:

// The implementation of this method by the parent class can be used to help us initialize the view (some initialization work is unknown or invisible, so we must call it );

// When rewriting methods inherited from the parent class, if you do not know how the parent class implements the method, remember to use super to call the implementation of the method;

For [super xxx] In the method to call the method of the parent class, if you do not need to add additional content, directly return YES with parameters.

 

// Add one:

-(Instancetype) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil;

This is the specified Initialization Method of the View Controller. No matter which method is called, the initialization method will be triggered;

-(Instancetype) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) attributes {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// complete the initialization operation exclusive to this class .} return self ;}

 

 

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.