Is there any was to get the NSIndexPath of a UITableViewCell's contentView subview?
In my case, I have a table view in which each row is split into 3 buttons. I can use the button tag to keep track of which column it is but I also need to know what row of the table view it is a subview of (when the user taps the button).
Because the button blocks the entire actual table view row, didSelectRowAtIndexPath is never called (which is expected), so I can't get it that way.
I have tried just [thisButton superview] but that doesn't seem to work. Any thoughts?
I assume the button is sending its UIControlEventTouchUpInside
event message to your view controller? Then you could do something like:
- (void)buttonPressed:(UIButton *)button
{
CGPoint location = [button.superview convertPoint:button.center toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
[self doSomethingWithRowAtIndexPath:indexPath];
}
One possible option is when making the cell for index path you can assign the tag to be 3 * row_number + <the tag number>
. then just divide the tag by 3 to get the row and %3 to get the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With