【问题标题】:Cell selection color in UITableView iOSUITableView iOS中的单元格选择颜色
【发布时间】:2017-04-28 19:24:06
【问题描述】:

我在使用 tableView 时遇到了这个问题:尽管我在选择一个单元格时将所有背景字段都设置为 darkText 颜色,但背景会变为浅色,如附件中所示。 我该如何解决这个问题?

【问题讨论】:

标签: ios swift uitableview ios10


【解决方案1】:

在 cellForRowAtIndex 中添加 cell.selectionStyle = .none。这将从该单元格中删除 selectionColor

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath)
    // do your cell customisation here..

    cell.selectionStyle = .none
    return cell
}

【讨论】:

    【解决方案2】:

    尝试以下方法在用户交互时禁用单元格选择。

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     let cell = tableView.dequeueReusableCell(withIdentifier: "yourCellIdentifier", for: indexPath)
    
     //Method 1: Simply disable the user cell interaction.
      cell.userInteractionEnabled = false
     //or
     //Method 2: use UITableViewCellSelectionStyle to none
      cell.selectionStyle = UITableViewCellSelectionStyle.none
    
    return cell
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多