Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get indexPath in a tableview from a button action in a cell?

I have a tableview with two actions in it, for the first on i use the delegate didSelectRowAtIndexPath, for the second one i would like to use an action on a button on my cell to do something else. My problem is that i don't succeed to get the indexpath ? What is the best practice to do that.

like image 925
Sylvain Bessot Avatar asked Sep 17 '11 04:09

Sylvain Bessot


1 Answers

If you have added the button to the cell as,

[cell.contentView addSubview:button];

then, you can get the index path as,

- (void)onButtonTapped:(UIButton *)button {

    UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
    NSIndexPath *indexPath = [tableView indexPathForCell:cell];
    // Go ahead
}
like image 60
EmptyStack Avatar answered Sep 17 '22 22:09

EmptyStack