Rob Bonner
Rob Bonner

Reputation: 9426

UIView on iPad with GroupTableViewBackgroundColor

I have a UIView that I have dropped inside of another UIView in IB (iPad version), I am doing this so I can control the background color of the region.

Odd thing is that if I set the background color of the UIView to GroupTableViewBackgroundColor, either in IB or code, the color is always white, it does not respect the color change, nor is it reflected in IB.

Has anyone seen this behavior and found a fix?

Thanks in advance.

Upvotes: 2

Views: 1108

Answers (2)

Rich Hoffman
Rich Hoffman

Reputation: 75

I think I know what you are saying. You want the view to be the same as a group table view even though it isn't a group table view. This is what I did:

UITableView *tv = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
UIView *backgroundView = tv.backgroundView;
[self.view addSubview:backgroundView];
[tv release];
CGRect backgroundFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[backgroundView setFrame:backgroundFrame];
[self.view sendSubviewToBack:backgroundView];

Upvotes: 2

kharrison
kharrison

Reputation: 3432

I am not sure if it is related to your problem but Apple introduced some changes to UITableView for iOS 3.2. They introduced a new property to UITableView defined as follows:

@property (nonatomic, readwrite, retain) UIView *backgroundView;

This new view sits behind the table cells, header and footer which can be confusing if you set the table view background color. As a quick workaround, if you just want to change the color, you can remove the new view:

tableView.backgroundView = nil;

You should then get the same behavior as on the iPhone when you set tableView.backgroundColor. (Of course this may all change with iOS 4.2).

Upvotes: 0

Related Questions