在 viewDidLoad 和 viewWillAppear 中调用 super 之前/之后放置代码
由于UIViewController中的关键字“did”和“will”,我不确定在viewDidLoad和viewWillAppear中调用super之前/之后的代码应该放在哪里,才能使代码有效运行。
例如:
- (void)viewDidLoad
{
[super viewDidLoad];
// Code is here because whatever
// setup in super should been done first
// before we can do anything
}
- (void)viewWillAppear:(BOOL)animated
{
// Code should be here to finish
// whatever we want to do in our view
// before calling super
[super viewWillAppear:animated];
}
这也可以应用于 didRotate 和 willRotate。这是正确的吗?
Due to the keywords "did" and "will" in UIViewController, I have am unsure where to put the code before/after calling super in viewDidLoad and viewWillAppear, in order to make the code run effectively.
For example:
- (void)viewDidLoad
{
[super viewDidLoad];
// Code is here because whatever
// setup in super should been done first
// before we can do anything
}
- (void)viewWillAppear:(BOOL)animated
{
// Code should be here to finish
// whatever we want to do in our view
// before calling super
[super viewWillAppear:animated];
}
This may be applied to didRotate and willRotate as well. Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从这里看一下这个答案 - [super viewWillAppear] 做什么,何时需要?
viewwillappear
-do-and-when-is-it-required作为一般规则,您应该始终首先调用
[super viewWillAppear:animated]
。Take a look at this answer from here - What does [super viewWillAppear] do, and when is it required?
viewwillappear
-do-and-when-is-it-requiredAs a general rule, you should always call
[super viewWillAppear:animated]
first.