2011-06-01 81 views
0

我试图点击时更改自定义单元格的背景颜色。这里是我的代码:自定义更改的backgroundColor的UITableViewCell不会显示

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath]; 
    if (...condition...) { 
     cell.backgroundColor = [UIColor clearColor]; 
    } else { 
     cell.backgroundColor = [UIColor yellowColor]; 
    } 
} 

现在,我做了调试和细胞.backgroundColor = [UIColor clearColor];被执行,但细胞保持黄色!这只发生在一些细胞(那些是黄色的,重复使用)。

有什么建议吗?

回答

0

您可以坚持更改的唯一方法是将其保存在某处,并在tableView:cellForRowAtIndexPath:方法中设置单元格时使用它。因此,维护一组具有黄色背景并设置单元格的单元格,检查它是否在集合中。如果是,则将其指定为黄色背景,如果不是,则将其设置为清除颜色。

0

更改自定义单元类中的单元格背景颜色,其中我们有一个方法setbackground :.

3

我得到它的工作。只好用 aCell.contentView.backgroundColor 而不是 aCell.backgroundColor

这奏效了我。

相关问题