Reputation: 3673
Each cell in my UITableView contains a custom UIButton. I can't seem to detect in which cell the currently pressed button lies. Method gets called but indexPath.row is always 0. Any suggestions?
-(IBAction)editButtonTouch:(id)sender {
UITableViewCell *cell = (UITableViewCell *)[sender superview];
NSIndexPath *indexPath = [[self tableView] indexPathForCell:cell];
switch([indexPath row]) {
case 0:
NSLog(@"first row");
break;
case 1:
NSLog(@"second row");
break;
}
}
Upvotes: 0
Views: 93
Reputation: 2361
This:
UITableViewCell *cell = (UITableViewCell *)[sender superview];
actually needs to be
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
But a better way of doing this is illustrated here: Detecting which UIButton was pressed in a UITableView
Upvotes: 1