首页 > 解决方案 > 在 iOS 14 中更改 UITableViewCell 的背景颜色

问题描述

在我的 iOS 应用程序中,我想更改所选UITableViewCell. 这就是我所拥有的,它运行良好,除了在 iOS 14 上我收到一条错误消息,说selectedBackgroundViewnil. 我需要在这里更改什么以便它也可以在 iOS 14 上运行?

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    self.selectedBackgroundView!.backgroundColor = selected ? UIColor.grey : .white
    menuLabel.textColor = selected ? UIColor.darkGrey : UIColor.primaryDark
    iconImageView.tintColor = selected ? UIColor.darkGrey : UIColor.primaryDark
}

标签: iosswiftuitableviewios14

解决方案


这对我有用:

self.contentView.backgroundColor = selected ? UIColor.grey : .white

推荐阅读