Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the background color of an UITableView within an UIPopoverController?

I am using iOS SDK 4.2. I have an UIPopoverController initialized with a navigation controller which is initialized with a view controller. One of the subviews of the view controller is a grouped table view. I would like to change the background color of the table view. However, if I do in the viewDidLoad method of the view controller

self.myTableView.backgroundColor = [UIColor blackColor];

the background does not changes, when the popover appears, the background of the table view is gray. Any clue? What's wrong with this approach? Thank you in advance.

like image 557
Massimo Cafaro Avatar asked Jan 14 '11 23:01

Massimo Cafaro


1 Answers

Grouped table views have a custom view in the backgroundView property. This custom view is what displays the background. If you want to change the background, you should create your own view and assign it there. In your case, you probably want something like the following:

UIView *bgView = [[[UIView alloc] init] autorelease];
bgView.backgroundColor = [UIColor blackColor];
bgView.opaque = YES;
self.myTableView.backgroundView = bgView;
like image 181
Lily Ballard Avatar answered Nov 15 '22 09:11

Lily Ballard