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

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

问题描述

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

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

我已经创建了一个 TableViewController,我想自定义 Cell Prototype.在 Cell Prototype 中,我添加了几个标签,我想用我自己的类进行自定义,这些类继承自 UITableViewCell (AreaListCell).在 Storyboard 中,对于 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".

在storyboard中,当我选择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.

结果是我可以创建 outlet(使用 Ctrl + 从 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:

现在可以在 cellForRowAtIndexPath: 方法中作为 cell.customLabel 访问它.

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

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

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