Xcode 生成的 .nib/.xib 和界面生成器 .nib/.xib 模板之间有什么区别?

发布于 2024-08-17 01:51:02 字数 410 浏览 4 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

倾城泪 2024-08-24 01:51:02

作为 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.

空宴 2024-08-24 01:51:02

XIB 文件基本上是一个未编译的 NIB 文件,XIB 始终可以在 Xcode 中编辑(除非它们已过时或损坏) 但大多数NIB都是压缩的(扁平的)并且无法打开。然而,较旧的 NIB 是包含一些源代码/存档的捆绑包,其中包括 designable.nib,它通常只是重命名的 XIB 文件和一个 keyedobjects.nib 这是另一个编译的NIB


NIB = Nxt I接口Builder

XIB = Xml I接口Builder


虽然新存档的 NIB 文件对于包括 Xcode 在内的大多数应用程序都无法打开,但它们仍然可能会被取消存档。我在 CharlesSoft 上发现了这个名为 NibUnlocker 的免费软件应用程序该网站可能会反汇编压缩的 Nib 文件并将其导出为 XIB 文档。该应用程序仍然存在相当多的错误,但有时根据 Nib 的内容非常准确。

(NibUnlocker 是一个非常不准确的名称,Nib 未锁定,而是已存档)


单击下载 Nib Unlocker


如果您想了解更多信息,可以阅读我在下面提供的有关 NIBXIB 格式的一些附加信息:

Nxt Interface Builder 剖析:

已存档NIB

压缩的 NIB 文件是一个分析起来很复杂的文件,但这并非不可能。这些文件的结构基于压缩的属性列表(以“bplist00”开头),并且其某些内容通过 NSKeyedArchiver 存档。由于 NIB 被格式化为属性列表,这允许一个小技巧:如果您实际上将 Nib 的扩展名更改为 .plist,例如。 ArchivedNib.nibArchivedNib.plist 您实际上可以在 Xcode 中打开它,将其视为属性列表。当您将 Nib 作为属性列表查看时,您可能会获得一些基本属性,例如 $version、$objects、$archiver 和 $top。

有用的注释

CFKeyedArchiverUID 对象实际上是一个重定向器,在 {value = xx} 中,该值是 $objects 数组中某个项目相对于起始位置的偏移数组。例如。 {value = 29},value = 29,结果将是 $object 数组中的第 29 项。在 Objective C 中,您可以使用以下方法从 NSArray 中检索该值:

+ (NSUInteger)valueForKeyedArchiverUID:(id)keyedArchiverUID {
  void *uid = (__bridge void*)keyedArchiverUID;
  NSUInteger *valuePtr = uid+16;
  return *valuePtr;}

就像这有帮助一样;-)

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 a keyedobjects.nib which is an other compiled NIB


NIB = Nxt Interface Builder

XIB = Xml Interface Builder


Although 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:

Nxt Interface Builder Anatomy:

Archived NIBs

A Compressed NIB file is complicated file to analyse but this is not impossible. The structure of these files are based off of a compacted property list (begins with "bplist00") and some of its contents are archived through NSKeyedArchiver. Since a NIB is formatted as a property list, This allows a small hack: if you actually change the extension of a Nib to .plist, eg. ArchivedNib.nib to ArchivedNib.plist You will actually be able to open it in Xcode viewing it as a Property List. When you view a Nib as a property list you will probably get a few base properties such as $version, $objects, $archiver and $top.

Useful Notes

A CFKeyedArchiverUID object is actually a redirector, in the {value = xx}, the value is an offset for a item in the $objects array from the start of the array. eg. <CFKeyedArchiverUID 0x60800002bc20 [0x7fffef6b8c30]>{value = 29}, value = 29, the result would be the 29th item in the $object's array. In Objective C you can retrieve this value from an NSArray with this method :

+ (NSUInteger)valueForKeyedArchiverUID:(id)keyedArchiverUID {
  void *uid = (__bridge void*)keyedArchiverUID;
  NSUInteger *valuePtr = uid+16;
  return *valuePtr;}

like if this helped ;-)

风启觞 2024-08-24 01:51:02

我不确定我是否在关注你的问题。当您在 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.

╰沐子 2024-08-24 01:51:02

听起来您通过设置视图出口并为文件所有者配置自定义类来正确配置视图 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.

甜点 2024-08-24 01:51:02

XIB 是 XML。区分它们并亲自找出答案。

XIBs are XML. Diff them and find out for yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文