你好,我正在使用自定义单元格进行 json 解析,我有一些标签值,我为每个单元格添加了按钮,我想在单元格上单击按钮时获取 ID。我的代码在这里
在我的 Tableview 代码中
cell.IDLabel.text= ID;
cell.cellButton1.tag=200+indexPath.row;
按钮操作
- (IBAction)didTapCellButton1:(UIButton *)sender {
int *myrow = sender.tag-199; // Now i know which row clicked with this code , But i want to know IDLabel value when this button clicked
}
我知道用 didTapCellButton1 操作代码点击了哪一行,但是我想在点击这个按钮时发送 IDLabel 值
谢谢!
最佳答案
您应该创建 @protocol
对于您的自定义单元格,类似于 - (void)myCustomCellDidSelectButton:(MyCustomCell *)cell
, 而不是在您的 ViewController 中实现委托(delegate)并设置 cell.delegate = self
在cellForRowAtIndexPath:
.现在,当您的按钮操作在单元格调用委托(delegate)方法内触发时。当你有手机时,即使没有你的数据源,你也可以检查你的 ID。
关于ios - 使用按钮操作发送单元格字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33964932/