我有一个类MTTableViewCell:UITableViewCell 该类中的init方法如下: 请注意,我将backgroundcolor设置为紫色。自定义TableView单元格未配置
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self)
{
[self setBackgroundColor:[UIColor purpleColor]];
}
return self;
// return [self initMVTableViewCellWithStyle:style reuseIdentifier:reuseIdentifier cellColor:nil];
}
我打电话从实现代码如下
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* identifier = @"one";
[self.tableView registerClass:[MVTTableViewCell class] forCellReuseIdentifier:identifier];
MVTTableViewCell *cell = [[MVTTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.textLabel.text = [self->datasource objectAtIndex:[indexPath row]];
return cell;
}
但是我没有看到在表视图中单元格的颜色的任何变化的委托下面的方法。 什么问题?
尝试它。没有工作。我正在使用alloc/init作为测试的一种方式。出院也没有工作。还有其他建议吗? – newbie
以下代码修复了它:cell.textLabel.backgroundColor = [UIColor clearColor]; cell.contentView.backgroundColor = [UIColor purpleColor];所以我猜这个文本标签的白色是阻止contentView的紫色。 – newbie