当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?


当前回答

而这是最好的和最简单的解决方案,以防止一行在选择期间显示高亮

cell.selectionStyle = UITableViewCellSelectionStyleNone;

我还想建议,偶尔可以简单地显示已选中的行,然后将其关闭。这将提醒用户确认他们打算选择的内容:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     [tableView deselectRowAtIndexPath:indexPath animated:NO];
...
}

其他回答

至少从iOS 6开始,你可以覆盖自定义单元格中的方法来阻止蓝色高亮。没有其他交互被禁用或影响。所有三个都必须被覆盖。

- (void) setHighlighted:(BOOL)highlighted
{
}

- (void) setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
}

- (void) setSelected:(BOOL)selected animated:(BOOL)animated
{
}

快速解决方案,自定义单元:

import Foundation

class CustomTableViewCell: UITableViewCell
{
  required init(coder aDecoder: NSCoder)
  {
    fatalError("init(coder:) has not been implemented")
  }

  override init(style: UITableViewCellStyle, reuseIdentifier: String?)
  {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    self.selectionStyle = UITableViewCellSelectionStyle.None
  } 
}

禁用UItableviewcell的高亮显示

cell.selectionStyle = UITableViewCellSelectionStyleNone;

并且不应该允许用户与单元格交互。

cell.userInteractionEnabled = NO;

你也可以从故事板中完成。单击表视图单元格,在表视图单元格下的属性检查器中,将Selection旁边的下拉菜单更改为None。

非常简单。在返回tableview单元格之前,使用表格视图单元格的style属性。

只需在返回表视图单元格之前编写这行代码 细胞。selectionStyle = .none