Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8.1 UITableview Background Colour always white

So I've tested this in iOS 7.1 and it works fine. I'm setting the background colour to clear on my tableview using the lines below.

    self.tableview = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.backgroundView = nil;
    self.tableview.backgroundColor = [UIColor clearColor];
    self.tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [self addSubview:self.tableview];

I'm also setting the tableFooterView to a new view to hide any left over unused cells using.

self.tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];

This works beautifully on iOS 7 but in iOS 8 I'm left with a white background colour for the space under the tableview. The superview the tableview sits inside also has a background colour of clear. Any ideas?

Added images below - I've had to obscure the client name

Working on iOS 7 Working on iOS 7

Not working on iOS 8.1enter image description here

like image 679
Matt Rees Avatar asked Nov 06 '14 16:11

Matt Rees


1 Answers

Apple document says

... In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the tableView:willDisplayCell:forRowAtIndexPath: method of your table view delegate.

You might need to use willDisplayCell UITableView delegate method to have a transparent background for your table view .

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath

{
      [cell setBackgroundColor:[UIColor clearColor]];
}
like image 174
neerajPK Avatar answered Oct 31 '22 10:10

neerajPK