ios - 如果您要查看 nib 文件的内部,它究竟是什么样子的?

标签 ios cocoa cocoa-touch nib

我刚开始学习 nibs 和 swift,对某些东西很好奇。我知道如果你有一个 main.storyboard 文件,那么首先加载一个 nib 到 Root View Controller ,然后是任何可能在该 View Controller 下分层存在的 View ,但是......我想知道一些事情。

当他们说一个 nib 被“加载”时,这是否意味着,根据您在界面构建器中构建的 Storyboard,一个函数调用了您想要加载的 ui 对象的实例?

如果不是,正确的看待这个问题的方式是什么?我正在尝试收集一个易于理解、准确的心理模型来描述所发生的事情。

谢谢!

最佳答案

What exactly does a nib file look like if you were to look inside?

往前走,往里看!它只是一个 XML 文件;人类完全可读。

I know that if you have a main.storyboard file, that a nib is loaded first fir the root view controller, then for any views that may exist hierarchically under that view controller

正确!更准确地说,将 Storyboard 中的每个“场景”视为包含两个 nib,一个包含 View Controller ,另一个包含其 View 、 View 的 subview 以及构成该场景的所有其他内容。

When they say a nib is 'loaded' does that mean that, a single function CALLS instances of the ui objects that you would like to load, based on the storyboard that you have built in the interface builder?

将 Nib 视为一堆潜在的对象实例。加载 Nib 会将这些潜在对象转变为实际实例。因此,加载 Nib 只是实例化和配置对象的另一种方式。 Nib 被“加载”仅仅意味着 Nib 被读取并且它所描述的对象被实例化和检索。这就是为什么您可以多次加载相同的 Nib 来获取这些对象的多个实例。

关于ios - 如果您要查看 nib 文件的内部,它究竟是什么样子的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40878498/

相关文章:

ios - 为什么某些 iOS Assets 无法以视网膜分辨率显示?

ios - 在 SpriteKit 中,当播放声音时,它会与加速度计混淆

iphone - tableView.contentInset 在 iOS 7 上损坏

cocoa - 向 WebView 添加上下文菜单

ios - 为什么我的 tableView 变量返回 nil?

ios - UIImage 中的绘图被扭曲

ios - 影响 UINavigationBar 的后退按钮方法 (iOS)

objective-c - 在 WebView 中显示 zip 文件的内容

cocoa - 如何在 Qt 中集成 Cocoa 代码

iphone - 进入后台时关闭应用程序