XIB 总是需要视图控制器吗?
如果我在 IB
中创建界面,我必须始终需要一个基本的 UIViewController
或者我可以直接跳到 UIView
吗?
截至目前,我的所有设计都是在 obj-c 中完成的,这使得工作变得更加忙碌。
如果我必须使用 UIViewController
,是否可以将 UIView
从中吸出(如果这就是我想要的)?
我只是希望能够从 XIB
中提取静态布局,而不是将它们放在 obj-c
中。
任何建议表示赞赏!
If I do an interface in IB
must I always need a base UIViewController
or can I just skip straight to a UIView
?
As of now I'm doing all my design in obj-c
which makes for a bit more busy work.
If I have to use a UIViewController
is there anyway to suck the UIView
out of it if that's all I want?
I just want to be able to pull out static layouts from XIB
instead of putting them together in obj-c
.
Any suggestions are appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UIViewController
有一个方便的initWithNib:bundle:
方法,使一切变得如此简单,但也有一些方法可以通过以下方式从 xibs 获取对象:(这里的 nib 数组包含的对象对应于 XIB 文件中存储的任何对象)。
UIViewController
has that handyinitWithNib: bundle:
method that makes everything so easy, but there are also ways to get objects from xibs via:(and the nib array here contains objects which correspond to whatever objects are stored in the XIB file).
不,如果 UIViewController 不能满足您的需求,您就不需要它。
初始化 UINib 后,使用它:
访问 nib 内容。使 nib 的根对象成为 UIView (或其子类)。如果您计划与文件所有者建立连接,则需要将文件所有者设置为适合上下文的类。
No, you don't need a UIViewController if it doesn't serve your needs.
After you have initialized a UINib, use its:
to access the nib contents. Make the nib's root object be a UIView (or subclass thereof). If you plan on making connections to File's Owner you will need to set File's Owner to a context-appropriate class.
不,您不需要将
UIViewController
与 XIB 关联。首先,不要向 XIB 添加视图控制器。然后,您经常使用
NSNib
或UINib
API 来访问 nib 的顶级对象 - 这样您就可以避免使用视图控制器并设置您想要的任何结构d 就像在 NIB 编辑器中一样,并根据需要以编程方式访问 NIB 中的对象。No, you don't need to associate a
UIViewController
with a XIB.First, do not add a view controller to the XIB. Then, you'd often use
NSNib
orUINib
APIs to access the top level objects of the nib -- so you can avoid a view controller and set up any structure you'd like in the NIB editor, and programmatically access the objects in the NIB as needed.在iOS 5中,不建议再使用XIB,你应该使用storyboard。
为了简单地回答你的问题,每个顶级视图都需要一个视图控制器来负责。
所有子视图都可以是视图控制器中的出口,并从那里进行处理。
In iOS 5, XIB are not recommended to be used anymore, you should use a storyboard instead.
And to simply answer your question, every top level view requires a view controller to be responsible for it.
All sub views can be an outlet in your view controller and be handled from there.