ViewController 与没有 Nib 文件的比较
当我在 Xcode 中创建 UIViewController 时,我可以决定添加 nib 文件。假设我此时不添加nib文件。我可以稍后简单地添加一个 nib 文件并将其命名为与 ViewController 相同的名称吗?
我问这个是因为我目前有一个具有特定背景颜色的表格视图。但是,当显示视图时,看起来像是使用了通用的 UITableView
。
所以就像我的nib文件被忽略一样,事实上,当我删除nib文件时,它仍然可以正常工作,但没有背景颜色。
When I create a UIViewController
in Xcode I can decide to add a nib file. Assuming I don't add the nib file at this time. Can I simple add a nib file later and give it the same name as the ViewController?
I am asking this because I currently have a tableview with a certain background color. However, when the view is displayed it looks like the generic UITableView
is used instead.
So it is like my nib file is ignored, in fact, when I delete the nib file, it still works the same, but without the background color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确信你可以。您必须在该 nib 文件中编辑文件所有者的类,以便它与您的自定义
UIViewController
类链接。I'm certain you can. You'll have to edit the class of the File's Owner in that nib file, so that it gets linked with your custom
UIViewController
class.我发现我的 nib 文件被忽略了。问题是我没有自己实例化我的 ViewController 错误,我通过在故事板中添加 NSObject 并将其类设置为我的类来在 IB 中定义它。
然而,像这样,对象只是
alloc] init]
'ed,但要加载笔尖,必须像这样分配它:一旦我这样做,笔尖就会加载,我可以配置我的Xcode 中的
UITableView
。万岁!I figured it out what my nib file was ignored. The problem was that I did not instantiate my ViewController myself bug I defined it in IB by adding a
NSObject
to my storyboard and setting its class to my class.However, like this the object is simply
alloc] init]
'ed but to load the nib, it has to be allocated like this:As soon as I do this the nib is loaded and I can configure my
UITableView
in Xcode. Hooray!