为什么我必须在自定义 NIB / XIB 中连接 IBOutlet 两次?

发布于 2024-10-15 07:18:37 字数 479 浏览 3 评论 0原文

我创建了一个自定义 myViewController 类,它具有默认的视图,以及子视图的 IBOutlet (topleftView)。

我创建了一个自定义 NIB/XIB 文件来加载此 myViewController.xib。在 XIB 文件中,我已将文件所有者设置为 myViewController,并将 UIViewController 标识类设置为 myViewController。

我的问题是为什么我必须从子视图中的 IBOutlet 连接并绘制对文件所有者和界面生成器中的 UIViewController 的引用?

只是想弄清楚这个问题,因为这是我第一次创建自定义 NIB/XIB。我通常只是在主窗口中完成所有操作,但我的应用程序变得太大,所以我想将事情分散开。

如果我在同一个 nib 文件中没有将一个 IBOutlet 与 UIViewController 和文件所有者建立多个连接,则会因 _EXC_BAD_ACCESS_ 错误而崩溃。

I have created a custom myViewController class and it has the default view, as well as an IBOutlet (topleftView) to a subview.

I have created a custom NIB/XIB file to load this myViewController.xib. Inside the XIB file I have set the file owner to myViewController and set the UIViewController identity class to myViewController as well.

My question is why do I have to hook up and draw a reference from the IBOutlet in the subview to both the file owner AND the UIViewController in interface builder?

Just trying to get my head around it since this is the first time I'm creating a custom NIB/XIB. I usually just did everything in MainWindow but my application is getting too large so I want to spread things out.

If I don't have these multiple connections for the one IBOutlet to both the UIViewController and File Owner in the same nib file I crash with _EXC_BAD_ACCESS_ errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

寂寞清仓 2024-10-22 07:18:37

“在 XIB 文件中我设置了
文件所有者到 myViewController ...”

我不确定你在这里做什么。我认为这就是问题所在。你的 XIB 顶层有多少项?它应该只是文件的所有者,第一个如果这里有另一个控制器对象,那就是你的问题了。

“...并设置
UIViewController 标识类
myViewController 也是如此”

这部分是正确的。要将自定义 UIViewController 连接到 XIB,请关注“文件所有者”,转到“身份检查器”,然后在“类”字段中查看“类身份”下。将其设置为'myViewController'(或任何您命名的名称)

此时,您应该为您设置的每个出口执行 1 次 Ctrl 拖动操作。

"Inside the XIB file I have set the
file owner to myViewController ..."

I'm not sure what you are doing here. I think this is where the problem is. How many items do you have on the top level of your XIB? It should just be File's Owner, First Responser and a View. If there is another controller object in here, that's your problem. Get rid of it.

"...and set
the UIViewController identity class to
myViewController as well"

This part is correct. To connect your custom UIViewController to the XIB, clock on your "File's Owner", go to the "Identity Inspector" then look under "Class Identity" at the "Class" field. Set this to 'myViewController' (or whatever you named it).

At this point you should do 1 ctrl-drag from your File's Owner for each outlet you have setup.

何其悲哀 2024-10-22 07:18:37

我的问题是为什么我必须挂钩
并从中吸取参考
子视图中的 IBOutlet 都
文件所有者和 UIViewController 中
界面构建器?

简短的回答:你不知道。只需将文件所有者的类设置为 UIViewController 子类的类名即可。

My question is why do I have to hook
up and draw a reference from the
IBOutlet in the subview to both the
file owner AND the UIViewController in
interface builder?

Short answer: You don't. Just set your File's Owner's class to the class name of your UIViewController subclass and you're set.

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