今天测试给我提了一个需求,就是在做用户筛选的时候,点击空白区域,回收筛选列表,我用了手势UITapGestureRecognizer,但是这时就出现了问题,因为列表是动态添加的,所以不能指定空白区域的frame,并且导致了UITableView的didSelectRowAtIndexPath方法不响应,通过百度,我发现原来是UITapGestureRecognizer的didSelectRowAtIndexPath的响应。
解决方法:
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog(@"gestureRecognizer = %@",NSStringFromClass([touch.view class]));
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UIView"])
{
return NO;
}
else if ([NSStringFromClass([touch.view class]) isEqualToString:@"InvestDetailSortButton"])
{
return NO;
}
return YES;
}
通过打印,找到能点击的区域的类名,通过类名来区分,这样就可以了。