I don’t understand when I need to invoke the overriden methods or it is just not required.
For example, for dealloc it is necessary
-(void) dealloc
{
...
[super dealloc];
}
For init also I guess..
-(void) init
{
[super init];
..
}
What about viewWillAppear ? and should I invoke the super method before or later my custom code ?
(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
thanks
The only way to know for sure if and when to call
superin an overridden method, is to read the documentation for that method.For the examples you gave:
init: The documentation states:dealloc: The documentation states:viewWillAppear:The documentation states:Every method is different. If you override viewDidAppear:, you must call super. If you override loadView, you must not. Basically, any time you override a method, you should check the documentation for that method to see if you should call super, and if so, whether you should do it before or after your own implementation.
If the documentation doesn’t say, then it’s up to you. After first scolding the author for his omission, do whatever you think makes sense. I’d generally be inclined not to call super if the documentation doesn’t say either way.