Placing code before/after calling super in viewDidLoad and viewWillAppear

拜拜、爱过 提交于 2019-12-13 02:19:23

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/7901302/placing-code-before-after-calling-super-in-viewdidload-and-viewwillappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!