如何将 IBOutlet 从 UITableViewController 直接连接到自定义单元格?

发布于 2024-12-13 07:01:37 字数 659 浏览 0 评论 0原文

几天前,我观看了视频教程,其中解释了如何在 UITableViewController 中使用自定义单元格。我了解到我可以直接在界面生成器中准备自定义单元格,因此我执行了以下操作:

我创建了一个 UITableViewController 并连接一个由 IBOutlet (UILabel) 组成的自定义类。之后,我切换了故事板并使用 UILabel 准备了自定义单元格。最后,我将标签从 UITableViewController 直接连接到我的自定义单元格。

会发生以下情况:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x400724860  <IBProxyObject: 0x4007872c0> => productLabel => <IBUIImageView: 0x401080220>>

不能直接连接吗?在 WWDC 2011 部分(第 309 场会议)的教程视频中,他们所做的正是我所做的。但有一个钩子:他们不显示背后的代码,他们只是像我上面解释的那样连接它。

为了更好地理解,我添加了一个屏幕截图,其中显示了我连接的内容: 在此处输入图像描述

A few days ago, I watched the video tutorial which explains how to use custom cells in an UITableViewController. I've learned that I can prepare a custom cell directly in the interface builder, so I did following:

I created a UITableViewController and connect a custom class which consists of an IBOutlet (UILabel). After that, I switched in my storyboard and prepared my custom cell with an UILabel. Finally I connect the label from UITableViewController to my custom cell directly.

The following happens:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x400724860  <IBProxyObject: 0x4007872c0> => productLabel => <IBUIImageView: 0x401080220>>

Isn't it possible to connect this directly? In the tutorial video of WWDC 2011 Section (Session #309) they do exactly what I did. But there is a hook: they don't show the code behind, they just connect it like I explained above.

For a better understanding I add a screenshot which shows, what i connect:
enter image description here

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

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

发布评论

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

评论(2

禾厶谷欠 2024-12-20 07:01:37

I had what turned out to be the same problem in this question. As the answerer of my question said, the problem is that the cell here is a prototype cell. A connection between a cell element and UITableViewController works fine for a table view with static cells since they are created at launch, but it doesn't make sense for prototype cells since many of them will probably be created...and they don't exist until cellForRowAtIndexPath is called. (This is a really poor error message, and Xcode probably shouldn't let you make a illegal connection like this.)

黑寡妇 2024-12-20 07:01:37

事实上,

我看过视频,他们没有按照你建议的方式连接。它们从单元格连接到单元格中的 UILabel。换句话说,它们有 UITableViewCell 的子类,并连接自定义对象中的 IBOutlet。在其基本形式中,您可以创建一个自定义单元类,只需声明接口并综合属性,就可以开始了。只需确保在情节提要中正确设置标识符和自定义类即可。

希望这有帮助。

Actually,

I have seen the video and they are not connecting the way you suggest. They are connecting from the cell to the UILabel in the cell. In other words, they have a subclass of UITableViewCell and are connecting those IBOutlets in the custom object. In its basic form, you can create a custom cell class and just declare the interface and synthesize the properties and you should be good to go. Just make sure you set up your identifier and custom class correctly in the storyboard.

Hope this helps.

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