如果有nib文件会调用loadView吗?
如果我重写loadView方法,则无论是否有nib文件,都会调用loadView。如果我不重写loadView并且有一个nib文件,它会被调用吗?
If I override the loadView method, loadView will be called whether there is a nib file. If I don't override loadView and there is a nib file, will it be called ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,loadView 负责根据视图控制器的类名从已知的包中自动加载 nib 文件。如果您重写
loadView
并且不调用[super loadView]
,则不会加载任何 nib。当 UIViewController 类的view
属性被调用并且为 nil 时,它将调用loadView
。另请注意,覆盖
loadView
并调用 super 很可能不是您想要的。loadView
用于设置self.view
属性,仅此而已。其他一切都应该发生在viewDidLoad
等中。Yes,
loadView
is responsible for loading nib files automatically from known bundles based on the class name of the view controller. If you overrideloadView
and don't call[super loadView]
, no nibs will be loaded. The UIViewController class will callloadView
when itsview
property is called and is nil.Also note that overriding
loadView
and calling super is most likely not what you want.loadView
is for setting theself.view
property, that's it. Everything else should happen inviewDidLoad
etc.是:
控制台:
Yes:
Console:
是的。无论捆绑包是否有 Nib,加载视图都将始终被调用。
loadView 将负责为 UIViewController 加载视图,该视图可以来自任何来源。
因此,它以两种方式查找视图
1.检查属性nibFile,如果您调用了,则可以设置该属性initWithNibName:捆绑包:
或者如果您有情节提要 - 情节提要也存储在 nib 文件内创建的所有视图
2。如果您没有从任何一个源设置 nib,那么您打算自己创建视图。在这种情况下,您可以稍后将此视图设置为查看控制器的视图属性。
Yes. Load view will be always gets called irrespective of bundle has a Nib or not.
loadView will has the job of loading view for UIViewController which can come from any source.
So, it look for views in two ways
1. Check the property nibFile which can be set if you have called initWithNibName:bundle:
or if you have storyboard - storyboard stores all the views created inside a nib file too
2. If you don't set nib from either of the source then you are planning to create views yourself. In this case you can set this view to view controller's view property later.