在自定义UITableViewCell上奇怪的突出显示
问题描述:
我有我自己的子类UITableViewCell
,我想在用户按下单元格时进行自定义。在自定义UITableViewCell上奇怪的突出显示
所以,我试图重写以下方法:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if (highlighted)
{
[self setBackgroundColor:[UIColor orangeColor]];
[self.optionLabel setTextColor:[UIColor whiteColor]];
}
else
{
[self setBackgroundColor:[UIColor clearColor]];
[self.optionLabel setTextColor:[UIColor orangeColor]];
}
[super setHighlighted:highlighted animated:animated];
}
如果我按住的细胞也能正常工作。但如果我快速点击单元格,我的UITableView
会捕获代表回调tableView:didSelectRowAtIndexPath:
,并且您看不到任何上述代码生效。
有没有人知道我在做什么错在这里?
答
嗯,你可以处理单元格被选中而不是突出显示的情况。例如:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
[self updateCell];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
[self updateCell];
}
- (void)updateCell {
if (self.highlighted || self.selected) {
[self setBackgroundColor:[UIColor orangeColor]];
[self.optionLabel setTextColor:[UIColor whiteColor]];
} else {
[self setBackgroundColor:[UIColor clearColor]];
[self.optionLabel setTextColor:[UIColor orangeColor]];
}
}