开发者

Question about inheritance

What code is correct and why ?

- (void)viewDidLoad 
{
    /*my code
     */
    [super viewDidLoad];
}

or

- (void)viewDidLoad 
{
    [开发者_运维知识库super viewDidLoad];
    /*my code
     */
}


It doesn't really matter that much. It's more about the way you'd like it. Would you want the super to respond first or the self? If it doesn't really matter that hard, do what you like.


It depends on whether you want your subclasses code to execute before or after the superclasses code for that method. I would say it's more common to do your own custom code after the call to super so that your subclasses code follows the superclasses code. Again, it depends on exactly what your trying to do.


I'd say the latter. You want your superclass's code to run first before you run your own.

Or, if you're completely replacing the function, you'd just comment out the call to the superclass's implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜