Transparent UITableViewCell flashing background when animating

ios, ios7, objective-c, uitableview

Solution

Create a subclass of UITableViewCell(Such as named: CustomCell), and override the method in CustomCell.m :

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if(self){
        // Initialization code
        [self setBackgroundColor:[UIColor clearColor]];
        UIView * bgView = [[UIView alloc] initWithFrame:self.frame];
        [bgView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5]];
        [self addSubview:bgView];
    }
    return self;
}

Remove willDisplayCell method in MasterViewController.m

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}

Change the `cellForRowAtIndexPath` method in MasterViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

Change the cell's class type in storyboard

Just have a try :D

Problem

I have a `UIViewController` with a custom background color. On top of it there's a `UITableView` with `UITableViewCells` that are semi-transparent (white color with opacity 0.5). The issue I'm blaming about and the one I'm banging my head against the wall is in iOS 7, when you have a `UITableViewCell` with semi-transparent background and you try to delete/insert/moving rows (so relying on an animation effect) the entire `UITableView` with its cells flashing for just 0.1 second and set cells background to a more transparent one. This is very annoying. The only thing I'm doing is set the background color of `self.view` with: ``` self.view.backgroundColor = [UIColor colorWithRed:0.4 green:0.5 blue:0.7 alpha:1]; ``` and set the background color of cells with: ``` - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5]; } ``` Here's a gif showing you the problem: And here's the super simple project: https://github.com/socksz/TransparentCellFlashing Please help me to solve this ridicolous issue! :P

Original source