1

I have a tableview and i have to use button in it.Based on tableViewCell i have to perform differnt action for different cell.How to distinguish which cell's button is clicked?

Blazer
  • 14,259
  • 3
  • 30
  • 53
Cyrus1
  • 226
  • 1
  • 5
  • Add them as subviews and set their tags equal to their indexPath's row. – CodaFi May 12 '12 at 16:04
  • 1
    Using tags is rubbish. See http://stackoverflow.com/questions/9274494/how-to-know-the-uitableview-row-number for a better way – jrturton May 12 '12 at 16:29

2 Answers2

2

All you have to do is set a tag for the button in cellforrowatindex delegate fo UITableViewCell and then you will have to check the tag for the same in the action of the button.

if(((UIButton *)sender).tag==someIntValue)
{
//your statement
}
Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25
1

You can set the tag property of the UIButton to the cell's indexPath.row:

button.tag = indexPath.row

Then in your button selector method, you can do:

-(void)handleButtonClick:(id)sender
{
   UIButton *button = (UIButton*)sender;
   indexPathRow = button.tag;
}
Snowman
  • 31,411
  • 46
  • 180
  • 303