简体   繁体   English

initWithNibName不能按预期工作

[英]initWithNibName Not working as expected

I am positive that I have missed something simple here. 我很肯定我错过了一些简单的事情。 I am attempting to load up a sub-view (modal view) as a separate controller in iOS. 我正在尝试将子视图(模式视图)加载为iOS中的单独控制器。 I have created a NIB file with a window that is pointing to my controller's view, the File's Owner class is set to my controller class, and I am attempting to call initWithNibName with the name of the nib file, but when I attempt to show it, it simply shows a blank view instead of the view I have build in the NIB file. 我创建了一个带有指向控制器视图的窗口的NIB文件,“文件的所有者”类设置为控制器类,并且我尝试使用nib文件的名称调用initWithNibName,但是当我尝试显示它时,它只是显示一个空白视图,而不是我在NIB文件中构建的视图。 Can it not be a window in the NIB if it is a modal sub controller? 如果它是模态子控制器,它可以不是NIB中的窗口吗? Or is there something else really obvious that I have missed? 还是我确实错过了其他明显的东西?

You have to ensure that the file owner's (which must be a UIViewController subclass) view property in your custom xib is set appropriately. 您必须确保自定义xib中的文件所有者(必须是UIViewController子类)的view属性设置正确。 If it is not, you'll get what you describe. 如果不是,您将得到您所描述的内容。 I know this is what you say you are doing but I am highly skeptical. 我知道这就是您所说的,但我对此表示高度怀疑。 It's either that, or you are not linking the right view to the view outlet of the file owner. 就是这样,或者您没有将正确的视图链接到文件所有者的view出口。 When in doubt, disconnect and reconnect. 如有疑问,请断开连接并重新连接。

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

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