The selectedBackgroundView modifies the contentView subviews
set cell.selectionStyle = UITableViewCellSelectionStyleNone
and override
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
if(highlighted) {
self.contentView.backgroundColor = colorYouWantWhenHighlighted;
} else {
self.contentView.backgroundColor = colorYouWantWhenUnhighlighted;
}
}
UITableViewCell
does two things automatically when highlighted/selected:
- Set all its subviews'
backgroundColor
to clear color(transparent). - Highlight all subviews that can be highlighted, for example,
UIImageView
.
To prevent the first problem, you have to override these two methods in your UITableViewCell
subclass:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
// Recover backgroundColor of subviews.
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected) {
// Recover backgroundColor of subviews.
}
}