在故事板中连接Cell Prototype的出口

编程入门 行业动态 更新时间:2024-10-13 02:19:18
本文介绍了在故事板中连接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的出口

本文发布于:2023-11-25 20:36:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:故事   Cell   Prototype

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!