UITableViewCellStyleSubtitle标签的BackgroundColor?

时间:2010-01-05 09:24:26

标签: uitableview background

我正在尝试创建一个以图像为背景的表格。 为实现这一目标,我从背景开始:

self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

这导致了一个背景图像,也出现在tablecells中。这不是我想要的,所以我试着设置单元格的backgroundColor:

cell.backgroundColor = [UIColor whiteColor];

这根本没有效果!!!嗯很奇怪。 所以我尝试了这个:

UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = backgroundView;
[backgroundView release];

这几乎可以。剩下的唯一问题是textLabel& detailTextLabel仍然显示它们背后的背景。 将这些标签上的backgroundColor设置为白色也不起作用。

我该怎么办?我哪里出错了?我正在尝试实现像worldClock应用程序一样的tableView。

1 个答案:

答案 0 :(得分:10)

要更改表格查看单元格的背景颜色,您需要在tableView:willDisplayCell:forRowAtIndexPath:而不是tableView:cellForRowAtIndexPath:中进行设置 否则它不会有任何影响,例如:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor whiteColor];
}