I have an UITableViewController that contains a tableView. I have added a tap gesture recognizer to this controller and I would like the action to happen when the user clicks everywhere except for the first row of the tableView (with indexPath.row == 0
).
I have seen the following related questions and answers (among others):
this one is concerned with detecting the tableView itself (therefore it will also detect its header / footer).
I has used this one (code below) before but the problem is that it computes an indexPath of
(0,0)
also if one clicks on the footer / header.
.
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gesture shouldReceiveTouch:(UITouch *)touch {
CGPoint buttonPosition = [touch locationInView:self.view];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
if (indexPath.row == 0) {
return NO; // will also be returned if I click on the header / footer
}
return YES;
}