Hey everyone, this seems like it should be a simple one; I really hope it is. As always, thanks in advance!
All I'm trying to do is add a background image to a grouped style tableview. I'm using the following method in viewDidLoad:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
Unfortunately, background.png seems to be drawn not only behind the cells, but also on the backgrounds of the cells and the headers as follows:
I know there are a few questions on this site addressing similar issues, but I'm afraid I couldn't get anything to work. http://stackoverflow.com/questions/894875/how-can-i-set-the-background-of-uitableview-the-tableview-style-is-grouped-to led me to add
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;
to viewDidLoad and to add
cell.backgroundView = nil;
cell.opaque = NO;
in configuring my cells. Needless to say, it didn't work. Adding
cell.backgroundColor = [UIColor clearColor];
didn't work either. And sadly, that was my last idea. I'd really like to be able to do this without adding the background in interface builder, if possible. I rather like doing as much as I can programmatically. I hope asking that isn't too greedy. Thanks again!
* * * EDIT: * * *
I came across another approach to accomplishing this, but ran into another problem. I added the following code to viewDidLoad:
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
[self.tableView.window addSubview:bgView];
[self.tableView addSubview:bgView];
[self.tableView sendSubviewToBack:bgView];
It looked promising, and it likely is, but unfortunately in gave me the following:
It looks as though it either wasn't sent to the back and the headers somehow show through or the cells went to the back with it. I'm not at all sure. Any advice here would be appreciated as well.
Here's where I found the code for the edit: http://stackoverflow.com/questions/2079002/add-uiview-behind-uitableview-in-uitableviewcontroller-code