Tuesday, 20 August 2013

Cell background color cannot be set to nil for search result

Cell background color cannot be set to nil for search result

I have a tableview with default background color headers. I also have a
filter bar, that filters the table results. When filtering, the headers
become all black bars.
If I set the background color to some specific color in
viewForHeaderInSection there is no unexpected behavior. If I set
backgroundColor to nil it works as expected, giving default color, but not
when I search.
Is somehow the default cell background color for a search results black?
Here is some code from my experiments:
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
static NSString *cellIdentifier = @"HeaderCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
//cell.contentView.backgroundColor = [UIColor colorWithRed:0.663
green:0.663 blue:0.663 alpha:1];
//[cell setBackgroundColor:[UIColor lightGrayColor]];
[cell setBackgroundColor:nil];
if(tableView == self.searchDisplayController.searchResultsTableView) {
[cell setBackgroundColor:[UIColor lightGrayColor]];
}
[[cell textLabel] setFont:[UIFont boldSystemFontOfSize:16]];
[[cell textLabel] setTextAlignment:NSTextAlignmentCenter];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
The code above will show default headers normally and lightGray after
searching. If I put the [cell setBackgroundColor:nil]; in the if statement
I get the black bars.
Does anyone have any idea what's going on here? Also, if there is no
elegant fix, can anyone tell me what the default background color is so I
can manually set it?
Thanks.

No comments:

Post a Comment