【发布时间】:2015-03-14 12:07:53
【问题描述】:
在尝试将数据从 tableview 自定义单元格传递到另一个 viewcontroller 时,我被困了几个小时。
更准确地说:
TableViewController1 将 CustomCell1 作为 Prototype Cell 类
CustomCell1 有 Button1、Button2、Label1 和 Label2
ViewController2 有 Label3
TableViewController1 填充良好,有 10-20 行数据,所有内容都在屏幕上正常显示。
当用户点击 Button1 或 Button2 时(据我所知,这会触发按钮的 IBAction 而不是选择行)我以编程方式从添加到 TableViewController1 的按钮的 IBAction 触发一个 segue。
我想不通的是当用户点击 Button1 时如何传递 Label1 文本,当用户点击 Button2 到 ViewController2 时如何传递 Label2 文本并在 Label3 中显示适当的文本。
由于 tableview 中没有选择行,如果可能的话,如何做到这一点?
谢谢!
科斯塔斯
【问题讨论】:
-
有一种既快速又便宜的方法 - 为按钮设置标签以根据行索引,例如 1001、1002 - 用于 button1 和 2001、2002.. 等用于 button2
标签: swift tableview segue tableviewcell