我添加了一个 UIImageView
在我的 UITableViewCell
的内容 View 的右侧.
我试图防止在用户触摸 UIImageView
时突出显示单元格(因为附加的手势识别器执行一些其他功能)。
我考虑过实现tableView:shouldHighlightRowAtIndexPath:
并返回 NO
,但我不确定如何轻松确定调用此方法时是否正在触摸图像。是否有捷径可寻?
最佳答案
试试这个:
- (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;
}
重要的部分是确保 ImageView 具有
userInteractionEnabled = YES
手势识别器有cancelsTouchesInView = YES
.这将导致
tapped
如果点击 ImageView ,则触发方法,但不会突出显示单元格。
关于iphone - 触摸内容 View 中的图像时防止 UITableViewCell 突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16866055/