2

UIImageView在我的UITableViewCell.

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

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

4

2 回答 2

0

为什么不添加UIButton自定义类型。会有点击按钮操作。不会影响单元格突出显示

防止表格单元格突出显示

cell.selectionStyle = UITableViewCellSelectionStyleNone;

或者

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
于 2013-06-01T05:37:14.187 回答
0

尝试这个:

- (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方法触发,但不会突出显示单元格。

于 2013-06-01T04:37:43.217 回答