当你点击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
  } 
}

其他回答

我正在用这个,它对我很有用。

cell?.selectionStyle = UITableViewCellSelectionStyle.None

在UITableViewDelegate协议中,你可以使用willSelectRowAtIndexPath方法 如果你不希望行被选中,返回nil。

同样的,你可以使用willDeselectRowAtIndexPath方法并返回nil,如果你不想让行取消选择。

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

cell.selectionStyle = UITableViewCellSelectionStyleNone;

试试这个

cell.selectionStyle = UITableViewCellSelectionStyleNone;

and

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

你也可以使用interfacebuilder设置选择样式。

你只需要把这段代码放到cellForRowAtIndexPath中

禁用单元格的选择属性:(在点击单元格时)。

cell.selectionStyle = UITableViewCellSelectionStyle.None