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


当前回答

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

didSelectRowAtIndexPath

以下

[tableView deselectRowAtIndexPath:indexPath animated:YES];

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

其他回答

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

cell?.selectionStyle = UITableViewCellSelectionStyle.None

试着输入:

cell.selected = NO;

它将在需要时取消选择您的行。

在Swift3中…

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let r = indexPath.row
    print("clicked .. \(r)")
    tableView.cellForRow(at: indexPath)?.setSelected(false, animated: true)
}

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

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

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

didSelectRowAtIndexPath

以下

[tableView deselectRowAtIndexPath:indexPath animated:YES];

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

你可以使用:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

UITableView的row at index path方法。

你还可以用:

[tableView deselectRowAtIndexPath:indexPath animated:NO];

在tableview中didselectrowatindexpath方法。