0
votes

EDIT: I was unclear when describing this. The UITableView that I'm loading is not a xib for a UITableView - it is a custom UIView which contains a UITableView (and is properly hooked up for delegates and outlets and whatnot)

I'm trying to set the background colour of a UITableViewCell from a tableview loaded from a nib.

First I tried setting the tableView background color property to UIColor clearColor. That didn't work, so then I changed my cellForRowAtIndexPath like so:

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"scoreCell";

UITableViewCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleSubtitle
            reuseIdentifier:CellIdentifier];
}

//First try
cell.backgroundColor = [UIColor clearColor];

//Added this after the others didn't work
cell.contentView.backgroundColor= [UIColor clearColor];

//Added this after
cell.textLabel.backgroundColor  = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
// Configure the cell.

cell.textLabel.text = [[leaderInfo objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.detailTextLabel.text = [[[leaderInfo objectAtIndex:indexPath.row] objectForKey:@"score"] stringValue];
cell.textLabel.adjustsFontSizeToFitWidth  =YES;


return cell;

}

Then after that didn't work, as per the documentation I tried:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Properties tested in all permutations
    cell.backgroundColor=[UIColor clearColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
1

1 Answers

0
votes

In order to set a cell color, you need to set the tableView's background color to clear and its backgroundView to nil.

- (void)viewDidLoad
{
    [self.tableView setBackgroundColor:[UIColor clearColor]];
    [self.tableView setBackgroundView:nil];
}