Gerardo
Gerardo

Reputation: 5830

iPhone viewDidLoad

When I override the method viewDidLoad, should I call it first and then write my code or is it the other way around?

Upvotes: 1

Views: 1170

Answers (2)

joshpaul
joshpaul

Reputation: 953

Call super's implementation. The approach is FIFO:

- (void)viewDidLoad
{
 [super viewDidLoad];
 // code...
}

- (void)viewDidUnload
{
 // code...
 [super viewDidUnload];
}

To gain a little more insight, look at Apple's documentation on View Controller: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html

Also see this similar (dup?) question and answer: `[super viewDidLoad]` convention

Upvotes: 1

Gerardo
Gerardo

Reputation: 5830

No, you don't need to call [super viewDidLoad].

Let's be real here: Apple is not going to break thousands of apps, including those based on their published sample code, by deciding an event they're not currently handling suddenly needs to do something that developers may or may not want to stop and it's critical that if you don't need different behavior you not stop the event.

If Apple needs to do something like this, they'd add a specific new event. For example, and this is a ridiculous example, viewConvertTo3D.

Call the super if it matches your pattern. In fact, you probably should make the effort to learn Apple's standard nesting pattern. Don't call it if it doesn't, or if you care more about keeping your sources small. Extra code is not future proofing.

from: here

Upvotes: 0

Related Questions