在故事板中连接Cell Prototype的出口 [英] Connect outlet of a Cell Prototype in a storyboard

查看:196
本文介绍了在故事板中连接Cell Prototype的出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是故事板的新手,所以我遇到了一些困难...

I'm a newbie with the Storyboard and so I have some difficulties...

我已经创建了一个TableViewController,我想自定义Cell Prototype。在Cell Prototype中,我添加了几个标签,我想用我自己的类来定制,它继承自UITableViewCell(AreaListCell)。
在故事板中,对于Cell Prototype我已经使用AreaListCell配置了自定义类,其样式为自定义。

I have created a TableViewController and I would like to customize the Cell Prototype. In the Cell Prototype I have added several Labels I would like to customize with my own class which inherits from UITableViewCell (AreaListCell). In the Storyboard, for the Cell Prototype I have configured the Custom Class with "AreaListCell" and its style is "Custom".

在故事板中,我选择了Cell Prototype然后是助手,助手显示我实现UITableViewController(AreasTableViewController)的类,而不是$
我的AreaListCell类。

In the storyboard, when I select the Cell Prototype and then the assistant, the assistant display my class that implements the UITableViewController (AreasTableViewController) and not
my "AreaListCell" class.

结果是我可以创建插座(使用Ctrl + Drag从Cell Prototype的标签)到AreasTableViewController类,但不能创建到AreaListCell类!
任何想法如何将Cell Prototype与我的AreaListCell类连接?

The consequence is I can create outlet (using Ctrl + Drag from the label of the Cell Prototype) to the AreasTableViewController class but not to the AreaListCell class ! Any idea how to connect the Cell Prototype with my AreaListCell class?

感谢您的帮助!

推荐答案

更新:从Xcode 4.6(可能更早)开始,您现在可以通过控制拖动创建出口了! - 这必须在接口部分或类扩展中完成(对于新的单元子类,默认情况下不存在类扩展。感谢Steve Haley指出这一点。

您无法通过拖动助手编辑器中的代码块来自动连接和创建插座,这很差,但您可以手动创建插座并连接它们。

You can't get the outlet automatically connected and created by dragging into the code block in the assistant editor, which is poor, but you can create the outlets manually and connect them then.

在你的单元子类接口中:

In your cell subclass interface:

@interface CustomCell : UITableViewCell

@property (nonatomic) IBOutlet UILabel* customLabel;

@end

在实现中正常合成。

在故事板中,选择单元格并转到连接检查器,您将看到新的插座。从那里拖到相关的原型中的元素:

In the storyboard, select the cell and go to the connections inspector, you will see the new outlet. Drag from there to the relevant element in your prototype:

现在可以b了在 cellForRowAtIndexPath:方法中以 cell.customLabel 的形式访问。

This can now be accessed as cell.customLabel in your cellForRowAtIndexPath: method.

这篇关于在故事板中连接Cell Prototype的出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆