I have noticed code from other sources where the author has not added the messages to super that are shown below. I usually add them both, but I was just curious as to what they do and am I right in always adding them?
-(void)viewDidLoad {
//... other code
[super viewDidLoad];
}
-(void)viewDidUnload {
//... other code
[super viewDidUnload];
}
gary
I would recommend always send
UIViewControllerdelegate messages tosuper(e.g.viewDidLoad,viewDidAppear). In some cases, it is unnecessary, if you are subclassingUIViewControllerdirectly for example.Some classes, e.g.
UITableViewController, require subclasses to do that, as it is documented: “You may override loadView or any other superclass method, but if you do be sure to invoke the superclass implementation of the method, usually as the first method call.”The call to
supergives the super class a chance to handle the event (e.g. reload the table data, animate the de-selection of the button, etc).Needless to say, you don’t need an explicit method whose sole job is calling super.