何时在viewWillAppear,viewDidDisappear等中调用super方法? [英] When do you call the super method in viewWillAppear, viewDidDisappear, etc...?

查看:66
本文介绍了何时在viewWillAppear,viewDidDisappear等中调用super方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIViewController的文档中,苹果建议在实现的某个时候调用超级例如,有关viewDidDisappear的讨论是:

In UIViewController's documentation, Apple suggests calling the super at some point in the implementation of viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear, etc... For example, the discussion on viewDidDisappear is:


执行与关闭或隐藏视图相关的附加任务
。如果您覆盖此方法,则
必须在实现中的某个时刻调用超级

我的问题是何时被调用是否重要,如果这样,调用它的正确时间是什么时候?应该根据您的特殊需要将super称为方法的第一行,最后一行还是中间的某个地方?

My question is does it matter when the super method is called and, if so, what is the correct time to call it? Should super be called as the first line of the method, the last line, or somewhere in the middle depending on your particular needs?

推荐答案

viewDidAppear 中首先调用 super ,以便您的调用被覆盖。

In viewDidAppear call super first so that your calls will override.

viewWillDisappear 中,这似乎是一个折腾,我进行了广泛的研究,找不到最终的答案,似乎是50/50。我决定在代码中最后调用 super ,就像在 super 一样> dealloc 。

In viewWillDisappear it seems to be a toss up, I have researched that extensively and could not find a conclusive answer and it seems to be 50/50. I have decided to call super last in my code in the same manner we call super last in dealloc.

这篇关于何时在viewWillAppear,viewDidDisappear等中调用super方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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