Xcode 生成的 .nib/.xib 和界面生成器 .nib/.xib 模板之间有什么区别?
我是 iPhone 开发新手,所以我一直在学习一些教程。我不明白的是 xib 如何适应工作流程。
在教程中,其中一项说明是创建一个新的 UIViewController 子类,并选择“XIB for User Interface”。在我的第一次尝试中,我忽略了检查该选项,我想也许我可以在 Interface Builder 中创建 xib,但这不起作用。 (我使用 Cocoa Touch View Template 创建了 xib,其名称与 UIViewController 相同,并将其保存到项目目录中,以便将其添加到项目中。)我什至更改了文件所有者的类标识并连接了视图出口(当我检查从 Xcode 生成的 xib 时,我注意到了两个区别。)
那么 Xcode 生成的 .xib (来自 UIViewController 模板)和 IB .xib 模板之间有什么区别?
I am new to iPhone development so I have been working through some tutorials. What I don't understand is how xib fit into the work flow.
In a tutorial, one of the instruction is to create a new UIViewController subclass with "XIB for User Interface" selected. On my first try, I neglected to check that option and I thought may be I can just create the xib in Interface Builder but that didn't work. ( I created the xib using Cocoa Touch View Template, with the same name as the UIViewController and saved it the into project directory so it was added to the project.) I even changed the Class Identify for the File's Owner and hooked up the view outlet (the two differences I noticed when I inspected the xib generated from Xcode.)
So what are the differences between Xcode generated .xib (from UIViewController Template) and the IB .xib template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
作为 Xcode 中新文件流程的一部分创建的 XIB 文件具有预设的文件所有者类,以及已连接的某些出口(视图)。否则,没有太大区别。
XIB files created as part of the New File flow in Xcode have their File's Owner class pre-set, as well as certain outlets (view) already connected. Otherwise, there's not much difference.
XIB 文件基本上是一个未编译的 NIB 文件,XIB 始终可以在 Xcode 中编辑(除非它们已过时或损坏) 但大多数NIB都是压缩的(扁平的)并且无法打开。然而,较旧的 NIB 是包含一些源代码/存档的捆绑包,其中包括
designable.nib
,它通常只是重命名的 XIB 文件和一个keyedobjects.nib
这是另一个编译的NIB虽然新存档的 NIB 文件对于包括 Xcode 在内的大多数应用程序都无法打开,但它们仍然可能会被取消存档。我在 CharlesSoft 上发现了这个名为 NibUnlocker 的免费软件应用程序该网站可能会反汇编压缩的 Nib 文件并将其导出为 XIB 文档。该应用程序仍然存在相当多的错误,但有时根据 Nib 的内容非常准确。
(NibUnlocker 是一个非常不准确的名称,Nib 未锁定,而是已存档)
单击下载 Nib Unlocker
如果您想了解更多信息,可以阅读我在下面提供的有关 NIB 和 XIB 格式的一些附加信息:
就像这有帮助一样;-)
The XIB File is basicly an uncompile NIB File, XIBs can always be edited in Xcode (unless they are outdated or corrupt) but most NIBs are compressed (flat) and are unopenable. However the older NIBs are bundles containing some source/archived including
designable.nib
which is often just the renamed XIB File and akeyedobjects.nib
which is an other compiled NIBAlthough the new archived NIB files are unopenable to most applications including Xcode, they can still potentially be unarchived. I found this freeware application called NibUnlocker On The CharlesSoft Website which can potentially disassemble a compressed Nib file and exports it as an XIB document. This application is still fairly buggy but it is sometimes very accurate based on the Nibs contents.
(NibUnlocker is a very inaccurate name, Nibs are not locked they are archived)
Click to Download Nib Unlocker
If You wish to know a bit more you can read some additional information I have provided below in regards to the NIB and XIB Formats:
like if this helped ;-)
我不确定我是否在关注你的问题。当您在 Xcode 中创建 xib 文件时,尝试编辑 xib 文件将显示 IB。因此,您实际上是在 Xcode 中使用 IB 编辑 xib 文件。我从未尝试过在 IB 中创建“独立”xib 文件,然后将其连接到 xcode 中的项目。
这种方法可能不起作用的唯一原因是,当您在项目上下文中创建 xib 文件时,会创建一些关联(例如 plist 中的“mainnib 文件基本名称”属性),当您创建该文件时,这些关联不会自动生成。尝试在 xcode 项目中使用独立的 xib 文件。
I'm not sure I'm following your question. When you created a xib file in Xcode, attempting to edit the xib file will bring up IB. So effectively you are using IB to edit the xib file in Xcode. I never tried creating a "stand-alone" xib file in IB and then hook it up to a project in xcode.
The only reason such an approach may not work is that when you create the xib file within the context of a project, there are associations created (such as "mainnib file base name" attribute in the plist) which will not be automatically generated when you attempt to use a standalone xib file with the xcode project.
听起来您通过设置视图出口并为文件所有者配置自定义类来正确配置视图 xib,但问题可能出在 UIViewController 子类上。
如果您的视图控制器子类直接实现了 -[UIViewController loadView] 方法,则会阻止 NIB 加载。在默认实现中,UIViewController 将加载与视图控制器同名的 NIB 文件。如果您重写此方法以不同的方式初始化视图(例如完全以编程方式),则加载 NIB 的默认实现将不会运行。
删除子类中 -[UIViewController loadView] 方法的重写,或确保名称匹配,可能会解决任何差异。
It sounds like you configured the view xib properly, by setting the View outlet and configuring the custom class for File's Owner, but perhaps the problem was with the UIViewController subclass.
If your view controller subclass had implemented the -[UIViewController loadView] method directly, it'd prevent the NIB from loading. In the default implementation, the UIViewController will load the NIB file with the same name as the view controller. If you override this method to initialize the view a different way (e.g. completely programmatically), the default implementation that loads the NIB won't run.
Deleting an override of the -[UIViewController loadView] method in your subclass, or ensuring the names match, might resolve any discrepancies.
XIB 是 XML。区分它们并亲自找出答案。
XIBs are XML. Diff them and find out for yourself.