我刚刚向UITapGestureRecognizer
添加了UITableView
,但处理程序(下方)只为indexPath
提供了'null'。
- (void)photoTapped:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
CGPoint tapLocation = [gestureRecognizer locationInView:self.itemsTableView];
NSIndexPath *tappedIndexPath = [self.itemsTableView indexPathForRowAtPoint:tapLocation];
//...
}
}
我不明白为什么。
答案 0 :(得分:3)
这样做:
- (void)photoTapped:(UIGestureRecognizer *)gestureRecognizer {
CGPoint location = [gestureRecognizer locationInView:self.view];
if (CGRectContainsPoint([self.view convertRect:self.itemsTableView.frame fromView:self.itemsTableView.superview], location))
{
CGPoint locationInTableview = [self.itemsTableView convertPoint:location fromView:self.view];
NSIndexPath *indexPath = [self.itemsTableView indexPathForRowAtPoint:locationInTableview];
if (indexPath) //use this code if needed
[self tableView:self.itemsTableView didSelectRowAtIndexPath:indexPath];
return;
}
// otherwise proceed with the rest of your gesture handling logic
}