objective-ciosviewdidloadviewdidunload

When to call [super viewDidLoad] and [super viewDIdUnload]?


In most of my code, I have the following setup for viewDidLoad and viewDidUnload:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //do stuff...
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    //do stuff...
}

However, I got to wondering... does it matter when you call viewDidLoad and viewDidUnload? Should each one be before or after I "do stuff"?

In other words, should each one be at the start or end of the method?

Edit: To further complicate things, this is Apple's default viewDidUnload method, which "seems" to suggest [super viewDidUnload] be called first...

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

Solution

  • I do call super last in destructors and first in constructors. viewDidUnload is kind of destructor so I would call it last. But in this case it's matter of taste.

    Also, just side note - viewDidUnload is deprecated since iOS 6.