6

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?

Community
  • 1
  • 1

2 Answers2

7

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.

abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70
2

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

Mikhail
  • 90
  • 7