为什么 UIViewController 有 xib 文件而 UIView 没有?
当我在 xcode 中创建一个新的 UIViewController 时,它会为我提供一个与界面关联的笔尖。但是,当我创建 UIView 时,它却没有。如果我对 MVC 的理解是正确的,视图实际上应该是包含界面元素(即笔尖)的部分,而视图控制器是将功能挂钩到它们控制的视图的部分。
我确信无论哪种方式我都能让它一起工作,所以这更像是一个探索性的问题。
这似乎是我缺少对如何使用这两个部分的一些基本理解的情况。我缺少什么?
When I create a new UIViewController in xcode, it offers to make me an associated nib for the interface. However, when I create a UIView, it does not. If my understanding of MVC is correct, views should really be the parts that contain the interface elements (i.e. the nib) while view controllers are the parts that hook the functionality to the views they control.
I'm sure I'll be able to get it working together either way, so this is more of an exploratory question.
This seems like a case where I'm missing some fundamental understanding of how these two parts should be used. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为UIView通常不会这样使用。
但是 如何关联笔尖 (.xib )带有 UIView 的文件?
Because UIView is usually not used in such way.
However How do I associate a nib (.xib) file with a UIView?
我最终得到的满足我兴趣的答案大致是这样的:
.xib 文件不一定要保存进入视图的每个 UIView(或子类),而只是在视图生命周期中不会更改的视图的一般轮廓。其他 UIView 更容易以编程方式创建,因为它们经常更改。
The answer I eventually got that satisfied my interest was roughly this:
.xib files aren't necessarily meant to hold every UIView (or subclass) that goes into the view, just a general outline of views that don't change during the life of the view. The other UIViews are much easier to create programmatically since they change often.
我也有类似的困惑。基本上(根据 MVC)视图包含在控制器内。在 iPhone 中,这意味着 UIViewController 有一个名为“view”的属性,它是一个 UIView 实例。
XIB 文件(这一点不常被提及)是一个序列化的 UIView 实例。它大致是一种 XML 子格式,表示 UIView 及其所有后续视图。因此,当您创建 UIViewController 时,会以 XIB 的形式创建 UIView 并绑定到该控制器。
因此,新的 UIView 没有 XIB,因为它们本质上是相同的东西......
I had a similar confusion. Basically (according to the MVC) the View is contained inside the Controller. In the iPhone this means that UIViewController has a property called 'view' which is a UIView instance.
A XIB file (and this is not mentioned often) is a serialised UIView instance. It is roughly an XML sub format which represents a UIView with all its subsequent views. So when you create a UIViewController, a UIView is created in the form of a XIB and bounded to that controller.
A new UIView therefore does not have a XIB because they are essentially the same thing...