简体   繁体   English

在loadView中添加UIControl子类会使iPhone应用程序崩溃

[英]Adding UIControl subclass in loadView crashes iphone app

I'm new to iPhone and experimenting with the platform. 我是iPhone新手,正在尝试该平台。 I have a root view controller which loads it's view from a nib. 我有一个根视图控制器,它从笔尖加载视图。 I accidentally uncommented the loadView method in this class, and now the app crashes - is this because if a view controller is initiated from a nib then you can never have a loadView implementation? 我不小心取消了此类中的loadView方法的注释,现在应用程序崩溃了-这是因为如果从笔尖启动视图控制器,那么您将永远无法实现loadView实现?

If you create your view using a nib file then you should override viewDidLoad and add your subviews there. 如果使用nib文件创建视图,则应覆盖viewDidLoad并在其中添加子视图。 You only want to override loadView when you are creating all your views programatically. 您只想在以编程方式创建所有视图时覆盖loadView。

Here's a link to the UIViewController documentation which has a little bit longer explanation under the entries for loadView and viewDidLoad. 这是指向UIViewController文档的链接,该文档在loadView和viewDidLoad的条目下有更长的解释。

I was confused by the same issue at first... 起初我对同一问题感到困惑...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM