views:

1388

answers:

4

In Apple's scrollView example they don't call that. I always thought that's a must. Why should I call that anyways?

+2  A: 

You don't have to call the [super viewDidLoad]

As far as I know, the viewDidLoad in the superclass (UIViewController) is only an empty function that gets called when the ViewController gets initialized with a nib-file.

So if you need to do any initializing, you should override this function and put your code there.

ullmark
+3  A: 

As Markus says, UIViewController doesn't do anything in its viewDidLoad method, so you don't have to call it. However, it's a good habit to get into, in case you change your inheritance structure and suddenly the class that used to inherit from UIViewController now inherits from something that does do something in the viewDidLoad method.

Paul Tomblin
+8  A: 

If you are overriding the method you should still call the method in the super. Even if the super class is not doing anything with it today, Apple might one day change the implementation and your code will mysteriously stop working. If you really don't need to do anything in that method, leave it out of your code entirely, and the super's method will run as usual, without any intervention on your part.

Caffeine Coma
+2  A: 

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.

Steven Fisher