initWithNibName 未按预期工作
我确信我在这里错过了一些简单的事情。我正在尝试将子视图(模态视图)加载为 iOS 中的单独控制器。我创建了一个 NIB 文件,其中一个窗口指向我的控制器视图,文件的所有者类设置为我的控制器类,并且我尝试使用 nib 文件的名称调用 initWithNibName,但是当我尝试显示它时,它只是显示一个空白视图,而不是我在 NIB 文件中构建的视图。如果是模态子控制器就不能是NIB中的窗口了吗?或者还有其他明显我错过的事情吗?
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. 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. Can it not be a window in the NIB if it is a modal sub controller? Or is there something else really obvious that I have missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须确保自定义 xib 中文件所有者(必须是
UIViewController
子类)的视图属性设置正确。如果不是,您将得到您所描述的内容。我知道这就是你所说的你正在做的事情,但我非常怀疑。要么是这样,要么您没有将正确的视图链接到文件所有者的view
出口。如有疑问,请断开连接并重新连接。You have to ensure that the file owner's (which must be a
UIViewController
subclass) view property in your custom xib is set appropriately. 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 theview
outlet of the file owner. When in doubt, disconnect and reconnect.