迅速改变标签
答
你可以继承你的单元格就像这样(然后cellForRow不会负责更新颜色,只能设置默认颜色)。
class YourTableViewCellClass: UITableViewCell {
@IBOutlet weak var yourLabel: UILabel!
override func setSelected(_ selected: Bool, animated: Bool) {
if(selected) {
self.contentView.backgroundColor = UIColor.red //or what you want as your cell bg color
self.yourLabel.backgroundColor = UIColor.green //or what you want
} else {
self.contentView.backgroundColor = UIColor.white //or what you want as your cell bg color
self.yourLabel.backgroundColor = UIColor.red //or what you want
}
} }
答
我明白了什么是,你把代码中的tableview改变颜色的didSelectRow方法,但它表明先前的颜色,而滚动。
因此,您需要在cellForRow方法中设置条件,例如
if(condition)
{
lbl.textcolor = x
}
else
{
lbl.textcolor = y
}
请问您可以使用您试过的东西吗?请花一些时间阅读:[问] –
您正在重复使用单元格,这是更改标签背景颜色的原因,您需要显示cellForRowAtIndexPath代码。 –
在自定义单元格类中选中单元格,以便在选择+ - 按钮时它具有颜色我如何使用cellForRowAtIndexPath更新颜色 –