2012-03-28 72 views
0

我用UITableView得到了一個應用程序。每個細胞都有附件。但我不能設置backgroundColor ti這個單元格。帶附件的UITableViewCell

enter image description here

我想在這方面設置backgrounColors:

cell.contentView.backgroundColor =[UIColor redColor]; 
cell.backgroundView.backgroundColor = [UIColor redColor]; 
cell.backgroundColor = [UIColor redColor]; 

但是,只有內容查看工作。我該怎麼做? Thnx

回答

2

第二種方式cell.backgroundView.backgroundColor = [UIColor redColor];沒有那麼錯。不幸的是,除非你創建一個backgroundView,否則沒有backgroundView。您必須創建一個UIView並將其設置爲單元格的背景。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
if (!cell) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"]; 
    UIView *background = [[UIView alloc] initWithFrame:CGRectZero]; 
    background.backgroundColor = [UIColor redColor]; 
    cell.backgroundView = background; 
}