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


当前回答

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

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
  } 
}

其他回答

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

你可以使用....

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

如果你想选择只闪光,而不是保持在选择状态,你可以调用,在

didSelectRowAtIndexPath

以下

[tableView deselectRowAtIndexPath:indexPath animated:YES];

它会刷新选中的状态并恢复。

这就是我所使用的,在cellForRowAtIndexPath中编写这段代码。

cell.selectionStyle = UITableViewCellSelectionStyleNone;

直接禁用突出显示TableViewCell到故事板