【问题标题】:How to disable UITableViewCell highlighting?如何禁用 UITableViewCell 突出显示?
【发布时间】:2016-07-20 18:49:35
【问题描述】:

我有一个带有透明表格视图的深灰色视图背景。我正在使用以下代码尝试在单击单元格时停止单元格突出显示。它可以工作,除非在最初单击单元格时,我看到一个突出显示。之后我过渡到另一个场景。当我回来时,单元格没有突出显示。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var selectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
    selectedCell.contentView.backgroundColor = UIColor.clearColor()
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

如何禁用仍在进行的初始单元格突出显示?

【问题讨论】:

  • 设置cell.selectionStyle = UITableViewCellSelectionStyleNone;点击此链接:link

标签: ios uitableview swift2


【解决方案1】:

设置 UITableViewCell 选择样式无

cell.selectionStyle = .None

【讨论】:

  • 这需要双击来选择。
【解决方案2】:

我发现其他答案对我不起作用,因为它们需要双击才能选择。这确实有效。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

tableView.deselectRow(at: indexPath, animated: true)

【讨论】:

    【解决方案3】:

    UITableViewDelegate 有处理单元格高亮的方法,可能 tableView(_:shouldHighlightRowAt:) 就是你要找的东西

    查看documentation 了解其他方法

    【讨论】:

      【解决方案4】:

      防止突出显示的最简单方法是将selectionStyle 设置为None。以下是如何实现这一点:

      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
          cell.selectionStyle = .None
          return cell
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-10-16
        • 2016-01-18
        • 2011-08-19
        • 2017-07-06
        • 2014-12-17
        • 1970-01-01
        • 2011-10-29
        相关资源
        最近更新 更多