默认突出显示表格视图单元格未显示

时间:2019-01-31 15:53:07

标签: ios swift tableview

我创建了一个表格视图,每个单元格中包含一个图像(覆盖整个单元格)和一个标题。但是,当我突出显示其中一个单元格时,什么也没有发生。它不会变暗,我认为这是默认设置。我尝试使用下面的代码来解决此问题,但这不起作用。

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
    let cell = (tableView.cellForRow(at: indexPath) as! MainPackCell)
    UIView.animate(withDuration: 0.4) {
        cell.packImageView.highlightedImage = cell.packImageView.image?.withRenderingMode(.alwaysTemplate)
        if #available(iOS 10.0, *) {
            cell.packImageView.tintColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.3)
        } else {
            // Fallback on earlier versions
        }
        UIView.animate(withDuration: 0.4, animations: {
            tableView.deselectRow(at: indexPath, animated: true)
        })
    }
}

1 个答案:

答案 0 :(得分:0)

填充TableVIew,并参考以下屏幕截图:---

enter image description here

使用它,它完成了:-男人 在cellForRowAt

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