在viewDidLoad和viewWillAppear中调用super之前/之后放置代码 [英] Placing code before/after calling super in viewDidLoad and viewWillAppear

查看:204
本文介绍了在viewDidLoad和viewWillAppear中调用super之前/之后放置代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于UIViewController中的关键字"did"和"will",我不确定在viewDidLoad和viewWillAppear中调用super之前/之后在哪里放置代码,以使代码有效运行.

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.

例如:

- (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.这是正确的吗?

This may be applied to didRotate and willRotate as well. Is this correct?

推荐答案

从这里看看这个答案- [super viewWillAppear]的作用是什么,什么时候需要? viewwillappear-何时需要它并做

Take a look at this answer from here - What does [super viewWillAppear] do, and when is it required?viewwillappear-do-and-when-is-it-required

通常,您应该始终先致电[super viewWillAppear:animated].

As a general rule, you should always call [super viewWillAppear:animated] first.

这篇关于在viewDidLoad和viewWillAppear中调用super之前/之后放置代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆