本文介绍了我应该在自己的代码之后还是之前调用[super superMethod]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[对不起我的英语不好]
[sorry for my weak english]
这个问题很简单(但是我很难在Google中表达它并找到它)...
The question is simple (but I have troubles in expressing it and finding it in google)...
我(在所有类似情况下,当我重写super方法时,不仅要使用此方法)应该使用:
Should I (in all similar cases, when I override the super method, not only this one) use:
- (void)viewDidLoad { /* my code */ [super viewDidLoad]; }或
- (void)viewDidLoad { [super viewDidLoad]; /* my code */ }还是取决于?
推荐答案在某些情况下,顺序无关紧要.在其他情况下,顺序至关重要.
in some cases the order will not matter. in others, order is critical.
一些概括将有助于:
- 在构造对象状态的一部分(viewDidLoad和init...)时,请先通过super调用.
- 破坏对象状态的一部分(viewDidUnload或dealloc)时,最后通过super调用.
- 如果我确定顺序无关紧要,那么我只需先通过super致电即可,以便于组织.
- when you are constructing a portion of the object's state (viewDidLoad and init...), call through super first.
- when you are destructing a portion of the object's state (viewDidUnload or dealloc), call through super last.
- if i am certain that the order does not matter, then i just call through super first for easier organization.
更多推荐
我应该在自己的代码之后还是之前调用[super superMethod]?
发布评论