问题描述:本人自己在cell上用view定义个一个高1pt的线并设置了背景。但出现了点击cell 线条不显示出来以及跳转出去 再调回来 显示不同步问题导致很不美观。
问题分析:UITableViewCell changes the background color of all sub views when cell is selected or highlighted. 这句话是官方文档描述cell的一句话
意思是cell选中状态或者高亮状态的时候 上面的子视图的背景色将会发生变化,背景是透明的时候不会出现上述状况。但是子视图设置了背景颜色之后 就会改变颜色 以至于我们看不到了他原来的背景。那么跳转出去 返回来的时候 选中状态和高亮状态消失了 背景色自然显示出来了但是 会有闪烁的问题导致了不美观 不流畅。
解决办法:那么我们怎么解决呢 ? 通过问题的分析 我们知道是cell选中的时候 和变成高亮状态搞的鬼。所以我们重写 选中状态和高亮状态,在里面直接设置view想要的背景色。
@implementation FKQuotepriceCell
- (void)awakeFromNib {
// Initialization code
[self setlinebackGroundcolor];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
[self setlinebackGroundcolor];
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
[super setHighlighted:highlighted animated:animated];
[self setlinebackGroundcolor];
}
-(void)setlinebackGroundcolor{
self.bgview.backgroundColor = [UIColor whiteColor];
self.line1.backgroundColor = [Getcolor getColor:@"#efefef"];// 设置背景颜色 Getcolor是自己写的把十六进制转换成uicolor的工具类
self.line2.backgroundColor = [Getcolor getColor:@"#efefef"];
self.line3.backgroundColor = [Getcolor getColor:@"#efefef"];
}
@end