iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效

UIScrollView中添加了一个手势

 UITapGestureRecognizer *_tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foregroundTapped:)];
    _tapRecognizer.delegate = self;
    [_foregroundScrollView addGestureRecognizer:_tapRecognizer];

之后didSelectRowAtIndexPath不会立即执行,要延时2-3秒才执行。这样肯定不行。网上找资料之后是因为被UITapGestureRecognizer 拦截了。解决办法是重写UIGestureRecognizerDelegate中的如下方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    }
    return  YES;
}

 

posted @ 2014-09-12 10:14  菜鸟程序猿  阅读(570)  评论(0编辑  收藏  举报