Cyrus1
Cyrus1

Reputation: 226

Button in UItableviewcell

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?

Upvotes: 1

Views: 379

Answers (2)

Abhishek Singh
Abhishek Singh

Reputation: 6166

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
}

Upvotes: 2

Snowman
Snowman

Reputation: 32061

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;
}

Upvotes: 1

Related Questions