简体   繁体   中英

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. Does anyone know how to do this?

  1. In didSelectRowAtIndexPath method you can get selected cell using cellForRowAtIndexPath using indexPath.row
  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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM