简体   繁体   中英

Send cell string value with button action

Hello I have working json parsing with custom cell and i have some label values and i added buttons for every cell and i want to take ID when clicked button on cell. My codes here

In My Tableview codes

  cell.IDLabel.text= ID;
  cell.cellButton1.tag=200+indexPath.row;

Button Action

- (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

}

i know which row clicked with didTapCellButton1 action code , But i want to send IDLabel value when this button clicked

Thank you !

You should create @protocol for your custom cell, something like - (void)myCustomCellDidSelectButton:(MyCustomCell *)cell , than implement delegate in your ViewController and set cell.delegate = self in cellForRowAtIndexPath: . Now when your button's action fires inside cell call delegate method. When you have cell you can check your ID even without your DataSource.

finally . I found easy way :)

My working codes here;

 cell.IDLabel.text= ID;

 int valueid = [cell.IDLabel.text intValue];

  cell.cellButton1.tag=valueid;

And when button clicked

 int myvalue = sender.tag;

I think will be help too many people

thanks !

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