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

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

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

发布评论

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

>www.elefans.com

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