Why do we need to call "Super viewdidload"

Source: Internet
Author: User
I. Why do I need to call "Super viewdidload"-(void) didreceivememorywarning {

[Super didreceivememorywarning];

}

-(Void) viewdidload {


[Super viewdidload];

}


In the above Code, what do I need to call the corresponding methods of the parent class?

Taking viewdidload as an example, viewdidload in the parent class (Super) will help you do some initialization work, for example, a is the parent class, B inherits, B creates and initializes some Members in the viewdidload method. c inherits B again. If C does not call the viewdidload method of super when calling viewdidload, some Members are not initialized, and problems may occur.



Ii. Call time of [Super viewdidload] and [Super viewdidunload:

 

(1) In iPhone/iPad programming, the viewdidload method is used to initialize the processing when trying to load the view in the controller.

There are two ways of writing in iPhone 4 and iPad basic development tutorial

Method 1:

-(Void) viewdidload {

[Super viewdidload];

// Other code

}

Method 2:

-(Void) viewdidload {

// Other code

[Super viewdidload];

}

However, I think the first method is more desirable. First, call the parent class to load the code before loading itself.

(2) The viewdidunload method is used to release resources when the view is detached, for example, releasing the output port and memory.

-(Void) viewdidunload {

// Release code, such as Self. xxx = nil;

[Super viewdidunload];

}


Why do we need to call "Super viewdidload"

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.