在viewDidLoad和viewWillAppear中调用super之前/之后放置代码

时间:2011-10-26 10:13:41

标签: ios viewdidload viewwillappear

由于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。这是对的吗?

1 个答案:

答案 0 :(得分:0)

从这里看一下这个答案 - What does [super viewWillAppear] do, and when is it required? viewwillappear - 什么时候做,

作为一般规则,您应该首先致电[super viewWillAppear:animated]