首页 > 解决方案 > 如何防止 UITableViewCell 在点击时被视觉取消选择?

问题描述

我使用以下设置我UITableViewCell的 s 的选定背景颜色:

    let backgroundColorView = UIView()
    backgroundColorView.backgroundColor = .red
    UITableViewCell.appearance().selectedBackgroundView = backgroundColorView

当我点击以选择它们时,单元格会短暂闪烁红色,然后返回到backgroundColor我设置的位置。

当我添加:

    if cell.isSelected
    {
        cell.backgroundColor = .red
    }

cellForRowAt indexPath,当我将其滚动到视线之外并再次返回时,单元格会变为红色。

如何确保点击后单元格立即保持红色?

编辑:如果我将以下代码添加到cellForRowAt,事情会按预期工作:

    let backgroundColorView = UIView()
    backgroundColorView.backgroundColor = .red
    cell.selectedBackgroundView = backgroundColorView

可能是iOS错误?

标签: iosswiftuitableview

解决方案


推荐阅读