XIB 总是需要视图控制器吗?

发布于 2025-01-01 07:51:51 字数 364 浏览 1 评论 0原文

如果我在 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 技术交流群。

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

发布评论

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

评论(4

定格我的天空 2025-01-08 07:51:51

UIViewController 有一个方便的 initWithNib:bundle: 方法,使一切变得如此简单,但也有一些方法可以通过以下方式从 xibs 获取对象:(

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"WhateverItsNamed" owner:self options:nil];

这里的 nib 数组包含的对象对应于 XIB 文件中存储的任何对象)。

UIViewController has that handy initWithNib: bundle: method that makes everything so easy, but there are also ways to get objects from xibs via:

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"WhateverItsNamed" owner:self options:nil];

(and the nib array here contains objects which correspond to whatever objects are stored in the XIB file).

囚我心虐我身 2025-01-08 07:51:51

不,如果 UIViewController 不能满足您的需求,您就不需要它。

初始化 UINib 后,使用它:

-instantiateWithOwner:options:

访问 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:

-instantiateWithOwner:options:

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.

神爱温柔 2025-01-08 07:51:51

不,您不需要将 UIViewController 与 XIB 关联。

首先,不要向 XIB 添加视图控制器。然后,您经常使用 NSNibUINib 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 or UINib 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.

浮萍、无处依 2025-01-08 07:51:51

在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.

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