问题描述
在中,苹果建议在实现的某个时候调用超级例如,有关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方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!