由于给View添加了触摸手势,导致TableView的didSelectRowAtIndexPath方法不触发
// 添加手势
UITapGestureRecognizer *tapGestrue = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestrueAction:)];
tapGestrue.delegate = self;
[self.view addGestureRecognizer:tapGestrue];
原因是我们添加的触摸手势与TableViewCell的点击手势冲突了,解决方法如下
1.遵守代理< UIGestureRecognizerDelegate >
2.实现代理方法
//解决手势与tableView选择冲突问题
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}
网友评论