Goppinath
Goppinath

Reputation: 10739

[tableView setBackgroundColor:[UIColor clearColor]] is not working only on iPad with iOS8

The statement:

[tableView setBackgroundColor:[UIColor clearColor]];

has no effect only on iPad especially with iOS8 with my existing App only. Just for a shake of test I have created a new Test App just to pin point the problem but it works. I have created a UIViewController class like this:

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self.view setBackgroundColor:[UIColor purpleColor]];

    UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 300, 300) style:UITableViewStylePlain];

    [aTableView setBackgroundColor:[UIColor clearColor]];

    [self.view addSubview:aTableView];
}

@end

and push ist with the following statement:

[self.navigationController pushViewController:[TestViewController new] animated:YES];

Pushing from the new Test App results like this (as I want):

enter image description here

but from my existing App (the real App where I have to implement) result like this:

enter image description here

Clearing the background color works perfectly under iOS7 iPhone and iPad even with iOS 8 iPhone. I have tried to find UIAppearance Proxy implementation that can influence the appearance but there isn't any.

I have already tried several SO proposals including setting the backgroundView to nil and they haven't helped.

Why it is working with new Test App and why it is not working with my Existing App? Anything to do with UINavigationController?

NB: Please don't mark as a duplicate because here the question is totally or slightly different than the existing ones.

Upvotes: 2

Views: 825

Answers (2)

vishnu
vishnu

Reputation: 715

UIView *bgView = [[UIView alloc] initWithFrame:cell.frame];
bgView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bgView;

Try the above code

Upvotes: 0

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

This is cell's color. So you have to change your cell's color. For more info see

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

Upvotes: 3

Related Questions