我有一个
UITableView
使用自定义单元格。
我有
MyTableViewCell : UITableViewCell
和
MyTableViewCellContentView : UIView
类。
我所做的基本上就是
AdvancedTableViewCells demo app from Apple
稍微改变一下,在一些行上,我想使用一个清晰的背景色来显示绘制文本后面的表格背景。
所以在
MyTableView
的
cellForRowAtIndexPath
我正在做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyCell";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.someValue = indexPath.section;
[cell finishedSetup];
return cell;
}
在我的
MyTableViewCell
的
finishedSetup
以下内容:
cellContentView = [[MyTableViewCellContentView alloc] initWithFrame:CGRectMake(0, 0, 320, 80) cell:self];
cellContentView.autoresizingMask = UIViewAutoresizingNone;
cellContentView.contentMode = UIViewContentModeRedraw;
[self.contentView addSubview:cellContentView];
和
在里面
MyTableViewCellContentView
我实现了
drawRect
方法。并计划不使用任何子视图,而是像Apple示例中那样绘制自定义内容。
CompositeSubviewBasedApplication
.
问题是,对于一些部分,我想使用
clearColor
backgroundColor
. 这是有效的,直到-
透明色
背景色
用于绘制
透明色
单元格,此时背景未被清除,仍将使用旧颜色。
如何重新绘制背景?
编辑
:
我忘了提,我正在设置背景色
我的表视图单元格内容视图
调用super的init后的init。通过:
self.backgroundColor = [UIColor clearColor];
我已经验证了这实际上是被调用的,并且使用clearcolor或redcolor按预期调用。
我也试过设置表格单元格的背景色,但没用。
编辑第2页
:这是我的DrawRect方法:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
static int i = 0;
[[NSString stringWithFormat:@"Cell %d", ++i] drawAtPoint:CGPointMake(3, 3) withFont:[UIFont boldSystemFontOfSize:16]];
}