如何在UITableViewCell中制作选择样式?

问题描述 投票:-1回答:1

我为我的 uitableviewcell 创建了 Xib 文件,在属性检查器中,我选择了默认的 SelectionStyle,但这并没有帮助我。所以我添加了附件类型.detailDisclosureButton。所以当我点击一个单元格时,我的单元格并没有高亮显示灰色,只有披露按钮显示灰色。

enter image description here

enter image description here

ios swift uitableview background-color
1个回答
0
投票

也许你可以试试这个。

extension CWScoreBoardViewController: UITableViewDelegate {

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      tableView.deselectRow(at: indexPath, animated: true)
  }

}

或者你可以试试这个。

extension CWScoreBoardViewController: UITableViewDataSource {

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "CWUsersTableViewCell", for: indexPath) as! CWUsersTableViewCell

      cell.selectionStyle = .none

      return cell
  }

}

© www.soinside.com 2019 - 2024. All rights reserved.