本文介绍了调用[super loadView]的副作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

loadView 的文档中,Apple声明:

In the docs for loadView, Apple states:

所以我试着调用 [super loadView] 在我的 loadView 方法。没有什么坏似乎发生,没有警告。我使用的是在 loadView 中编程的视图,而不是来自NIB。

So I tried calling [super loadView] in my loadView method. Nothing bad seemed to happen and there was no warning. I'm using a view created programatically, in loadView, not from a NIB.

当我调用 [super loadView]

推荐答案

调用 [super loadView] 会导致 UIViewController 实现 loadView 运行。除此之外,如果已经提供了 nibName ,这是从NIB加载视图的方法。所以如果你调用super last,它可能会覆盖你在自己的子类中所做的所有视图设置。如果你先调用super,这不会是一个问题...除非你有 -awakeFromNib 或任何代码。

Calling [super loadView] will cause the UIViewController implementation of loadView to run. Among other things, this is the method that loads a view from a NIB, if a nibName has been provided. So if you were to call super last, it might overwrite all the view setup you did in your own subclass. If you call super first, this wouldn't be a problem... unless you have any code in -awakeFromNib or something.

基本上,你不应该调用 super ,因为如果你以编程方式加载你的视图,超类中做的工作都不是你想要保留的工作。最多你会丢掉一堆工作。在最坏的情况下, UIViewController 可能会设置一些状态,对视图的原点做出假设。

Basically, you shouldn't call super because if you're loading your view programmatically, none of the work done in the superclass is work you want to keep. At best, you're throwing away a bunch of work. At worst, UIViewController may set up some state in there that makes assumptions about the origin of the view.

不需要它,所以不要这样做。

You don't need it, so don't do it.

这篇关于调用[super loadView]的副作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 04:38