I have a UITableView with custom cells. Within each UITableViewCell, there is a UIButton. I'm attempting to find out which cell the button is located in when it is tapped. To do this I've done this:
- (IBAction)likeTap:(id)sender {
UIButton *senderButton = (UIButton *)sender;
UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview];
UITableView* table = (UITableView *)[buttonCell superview];
NSIndexPath *pathOfTheCell = [table indexPathForCell:buttonCell];
NSInteger rowOfTheCell = [pathOfTheCell row];
NSLog(@"rowofthecell %d", rowOfTheCell);
I thought this would work fine, but when indexPathForCell is called, an exception is thrown.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell indexPathForCell:]: unrecognized selector sent to instance 0x756d650'
Any ideas about what I've done wrong? Thanks!