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

发布于 2024-12-11 20:34:10 字数 546 浏览 0 评论 0原文

由于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‖放下 2024-12-18 20:34:10

从这里看一下这个答案 - [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-required

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文