防止在触摸内容视图中的图像时突出显示UITableViewCell

问题描述:

我在我的UITableViewCell的内容视图的右侧添加了UIImageView防止在触摸内容视图中的图像时突出显示UITableViewCell

我试图防止在用户触摸UIImageView(因为附加的手势识别器执行一些其他功能)时突出显示单元格。

我想过如何实现tableView:shouldHighlightRowAtIndexPath:并返回NO,但我不确定如何在调用此方法时轻松确定图像是否被触摸。是否有捷径可寻?

+0

我们能否看到您的实施?您是否设置了'imageView.userInteractionEnabled = YES;' – bbarnhart

+0

是的,用户交互已启用。实际上与UIImageView进行交互没有任何问题 - 只是在这样做时单元格可能仍然会突出显示。 – rrbrambley

+0

如果用户点击单元格而不是右侧图像,单元格是否应该突出显示/选择? – bbarnhart

试试这个:

- (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方法在点击图像视图时触发,但单元格不会突出显示。

你为什么不加入A型UIButton custom.Will有水龙头按钮action.Will不影响细胞亮点

的TableCell的

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
防止亮点