ios - 使用按钮操作发送单元格字符串值

标签 ios objective-c uitableview

你好,我正在使用自定义单元格进行 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 = selfcellForRowAtIndexPath: .现在,当您的按钮操作在单元格调用委托(delegate)方法内触发时。当你有手机时,即使没有你的数据源,你也可以检查你的 ID。

关于ios - 使用按钮操作发送单元格字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33964932/

相关文章:

ios - 跟踪 iOS 应用程序在后台的时间

iOS 蓝牙问题

ios - 以编程方式将 UITableViewCells 固定到所有侧面

objective-c - 按键盘按钮时 SearchBar 不起作用

ios - 通过单个字符串嵌套 UITableView

ios - 滚动时 UITableView 奇怪的行为

iphone - 自定义 UISwitch 和 App Store 批准

ios - 装有 iOS 7 的 Sphero

ios - 自定义 UITableViewCell 未出现

ios - 如何在 Swift 中更改 UITableView 单元格文本宽度