问题描述
几天前,我观看了视频教程,该教程解释了如何在UITableViewController中使用自定义单元格。我已经知道我可以直接在界面构建器中准备一个自定义单元格,所以我做了以下操作:
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:
我创建了一个UITableViewController并连接一个自定义类,它包含一个IBOutlet(UILabel)。之后,我切换了我的故事板并用UILabel准备了我的自定义单元格。最后,我将标签从UITableViewController直接连接到我的自定义单元格。
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.
发生以下情况:
Couldn't compile connection: <IBCocoaTouchOutletConnection:0x400724860 <IBProxyObject: 0x4007872c0> => productLabel => <IBUIImageView: 0x401080220>>
是否可以直接连接?在WWDC 2011部分(会话#309)的教程视频中,他们完全按照我的方式行事。但是有一个钩子:他们没有显示背后的代码,他们只是像我上面解释的那样连接它。
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:
推荐答案
实际上,
我看过这个视频并没有以你的建议方式连接。它们从细胞连接到细胞中的UILabel。换句话说,它们有一个UITableViewCell的子类,并在自定义对象中连接这些IBOutlet。在它的基本形式中,您可以创建一个自定义单元类,只需声明接口并合成属性,您应该很高兴。只需确保在故事板中正确设置标识符和自定义类。
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.
希望这会有所帮助。
这篇关于如何将IBOutlet从UITableViewController直接连接到自定义单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!