我UIImageView
在我的UITableViewCell
.
我试图防止在用户触摸单元格时突出显示UIImageView
(因为附加的手势识别器执行一些其他功能)。
我考虑过实现tableView:shouldHighlightRowAtIndexPath:
和返回NO
,但我不确定如何轻松确定调用此方法时是否正在触摸图像。是否有捷径可寻?
我UIImageView
在我的UITableViewCell
.
我试图防止在用户触摸单元格时突出显示UIImageView
(因为附加的手势识别器执行一些其他功能)。
我考虑过实现tableView:shouldHighlightRowAtIndexPath:
和返回NO
,但我不确定如何轻松确定调用此方法时是否正在触摸图像。是否有捷径可寻?
为什么不添加UIButton
自定义类型。会有点击按钮操作。不会影响单元格突出显示
防止表格单元格突出显示
cell.selectionStyle = UITableViewCellSelectionStyleNone;
或者
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
尝试这个:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// Add tap gesture recogniser to cell's image view
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
tap.cancelsTouchesInView = YES;
cell.theImageView.userInteractionEnabled = YES;
[cell.theImageView addGestureRecognizer:tap];
return cell;
}
重要的部分是确保图像视图具有userInteractionEnabled = YES
和手势识别器具有cancelsTouchesInView = YES
。
如果点击图像视图,这将导致该tapped
方法触发,但不会突出显示单元格。