views:

2311

answers:

2

Hi,

When I set the backgroundColor for my UITableView it works fine on iPhone (device and simulator) but NOT on the iPad simulator. Instead I get a light gray background for any color I set including groupTableViewBackgroundColor.

Steps to reproduce:

  1. Create a new navigation-based project.
  2. Open RootViewController.xib and set the table view style to "Grouped".
  3. Add this responder to the RootViewController:

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    }
  4. Select Simulator SDK 3.2, build and run.
  5. You will get a black background (device and simulator).
  6. Select your target in the project tree.
  7. Click on Project : Upgrade Current Target for iPad.
  8. Build and run.
  9. You will get a light gray background.
  10. Revert the table view style to Plain and you will get a black background.

Thanks for your help!

+10  A: 

Try one of these.

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease];
drawnonward
I don't know if there are side effects but it works! Thanks! self.tableView.backgroundView = nil;
rjobidon
Wow it works! Why is this?
Tejaswi Yerukalapudi
VERY VERY IMPORTANT: This works only with SDK 3.2. For backward compatibility with 3.1.3. and earlier you must check if the table view responds to the backgroundView property: if ([self.tableView respondsToSelector:@selector(backgroundView)]) self.tableView.backgroundView = nil; otherwise you app will crash and exit abruptly, you can trust me!
rjobidon
+2  A: 

Thanks a lot for this solution. I applied this on a UITableView property with IBOutlet in a UIViewController and it works well like:

[panelTable setBackgroundView:nil];
[panelTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[panelTable setBackgroundColor:UIColor.clearColor]; // Make the table view transparent
Alexander