iphone - 触摸内容 View 中的图像时防止 UITableViewCell 突出显示

标签 iphone ios uitableview

我添加了一个 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/

相关文章:

iphone - 将 iPhone 中录制的声音从一种格式转换为另一种格式,例如将 wav 转换为 mp3

iphone - 随着表变大,Sqlite3 插入到非索引表需要更长的时间

iphone - iTunes Connect 应用程序图标自动更改

swift - NSInternalInconsistencyException : Invalid Update using tableview CoreData

ios - 如何让plist中的特定项目显示在tableView中

iphone - 在 iPhone 上解压 rar

ios - 使用 SimpleAudioEngine 按顺序播放声音

ios - 使用 performSegueWithIdentifier Swift 2.1 时出错

ios - 如何使用 Alamofire 和 SwiftyJSON 将 JSON 字典元素中的所有元素附加到数组

iphone - UITableViewCell 背景 View 中的 UIButton