This is the .m file of my UITableViewCell.
#import "ContentCardTableViewCell.h"
#import <QuartzCore/QuartzCore.h>
@implementation ContentCardTableViewCell
- (void)awakeFromNib {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
[self setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected) {
[self setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}
}
@end
But one view in this UITableViewCell disappears on selection. I have tried this and this and many more but nothing helped. Is there something I am missing?
I had a similar issue.
If i set selectionStyle to UITableViewCellSelectionStyleNone works fine, problem solved. ie;
in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
add
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
before returning the cell.Hope it works.
you forgot to recover state after deselecting of cell
if (selected) {
[self.contentView setBackgroundColor:[UIColor clearColor]];
// Recover backgroundColor of subviews.
}else{
[self.contentView setBackgroundColor:[UIColor whiteColor]]
}
PS: it's preferred to setup color of cell.contentView
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.