should I call the [super superMethod] after my own code or before it?
[sorry for my weak english]
The question is simple (but I have troubles in expressing it and finding it in google)...
Should I (in all similar cases, when I override the super method, not only this one) use:
- (void)viewDidLoad
{
/*
my code
*/
[super viewDidLoad];
}
or
- (void)viewDidLoad
{
[super viewDidLoad];
开发者_运维技巧/*
my code
*/
}
or does it depend?
in some cases the order will not matter. in others, order is critical.
some generalizations which will help:
- when you are constructing a portion of the object's state (
viewDidLoad
andinit...
), call throughsuper
first. - when you are destructing a portion of the object's state (
viewDidUnload
ordealloc
), call throughsuper
last. - if i am certain that the order does not matter, then i just call through
super
first for easier organization.
It depends on the method; e.g. -[super init]
(before) vs -[super dealloc]
(after).
精彩评论