代码之家  ›  专栏  ›  技术社区  ›  Ram Gandhi

如何检测单元格下方表格视图中的点击/触摸?

  •  1
  • Ram Gandhi  · 技术社区  · 13 年前

    我想检测用户何时敲击中的剩余空间 UITableView 低于 tableViewCell s

    我的主要目的是为了应对 searchBar 当用户点击空的TableView区域时。

    它没有响应 UITouch 事件。我还试着添加 UITapGestureRecognizer ,但它已经覆盖了整个表视图。

    任何帮助都将不胜感激。

    1 回复  |  直到 13 年前
        1
  •  2
  •   Jake    12 年前

    除了添加UIMapGestureRecognizer之外,还需要实现一个委托方法,并将该委托分配给手势识别器。首先在视图控制器中的某个位置:

    UITapGestrueRecognizer *tapRecognizer = ...;
    tapRecognizer.delegate = self;
    

    下面是要实现的委托方法:

    -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
        CGPoint location = [gestureRecognizer locationInView:self.tableView];
        NSIndexPath *indexPath = self.tableView indexPathForRowAtPoint:location];
        return (indexPath == nil);
    }
    

    delegate方法检查敲击是否发生在单元格中,如果没有,它不会开始识别敲击,以便让表视图有机会解释手势。

    推荐文章