1

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

laurent
  • 88,262
  • 77
  • 290
  • 428
Gerardo
  • 5,800
  • 11
  • 66
  • 94
  • It sounds like this is the same question as http://stackoverflow.com/questions/2148450/viewdidload-unload-messages-to-super http://stackoverflow.com/questions/824695/do-i-always-have-to-call-super-viewdidload-in-the-viewdidload-method and a number of other questions. – Jonah Jan 16 '11 at 23:16

2 Answers2

1

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

Community
  • 1
  • 1
joshpaul
  • 953
  • 8
  • 12
0

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

Community
  • 1
  • 1
Gerardo
  • 5,800
  • 11
  • 66
  • 94