简体   繁体   English

如何在表格视图单元格中单击按钮时获取标签值

[英]How to get label value in table view cell on button click in cell

I have a prototype cell which with a button and a label in it. 我有一个带有按钮和标签的原型单元。 The text of the label changes for each cell. 标签的文本随每个单元格而变化。 I have set up an @IBAction for the button and would like to get the text for the label in the cell in which the button in pressed. 我为按钮设置了一个@IBAction ,并希望在按下按钮的单元格中获取标签的文本。 Does anyone know how to do this? 有谁知道如何做到这一点?

  1. In didSelectRowAtIndexPath method you can get selected cell using cellForRowAtIndexPath using indexPath.row 在didSelectRowAtIndexPath方法中,您可以使用带有indexPath.row的cellForRowAtIndexPath获取选定的单元格
  2. when you get selected cell object you can access that label which present inside the cell. 当您获得选定的单元格对象时,您可以访问该单元格中存在的标签。

I hope it will help you. 希望对您有帮助。

- (IBAction)buttonHandler:(id)sender{
    UIButton *button = (UIButton *)sender;
    UITableViewCell *cell = (UITableViewCell *)button.superview;
    println("%@",cell.textLabel.text)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS-如何通过单击表格单元格中的按钮从表格单元格获取标签值? - ios - How to get label value from table cell by click button in table cell? 如何从动态表格视图单元格 swift 获取按钮单击时的文本字段值 - How to get textfield value on button click from dynamic table view cell swift 如何在表视图单元格中的按钮单击上获取标签以进行prepareForSegue - How to get label on button click in tableview cell for prepareForSegue 滚动后表格视图单元格标签更改并在其中获得错误的值该如何解决? - Table view cell label get changed after scrolling and get wrong value in it how to solve it? 如何从iPhone的“表格”视图中获取选定单元格的单元格值 - how to get the cell value of a selected cell from Table view in iPhone 单元格标签在表视图中未捕获值 - Cell label Does not catching value in table view 单击表格视图单元格上的按钮时如何获取indexPath.row? - How to get the indexPath.row when I click a button on a table view cell? 单击同一收集单元中的按钮时如何在收集单元中获取标签 - How to get the label in the collection cell when click a button in the same collection cell 我如何单击UI表格视图单元格(自定义单元格)内的按钮,然后转到其他ViewController - how can I click button inside UI table view cell (custom cell ) and then goto other viewcontroller Swift - 如何在按下不同自定义单元格中的按钮时获取自定义单元格标签的值? - Swift - How to get the value of a custom cell label when pressing a button in a different custom cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM