自从升级到 iOS7 以来,我遇到了一个问题,当我尝试更改特定表格 View 单元格的背景颜色时,它不会为正确的单元格着色(通常是指定的单元格以及其他单元格) 。正如您从下面的代码中看到的,我定义了要突出显示的类型,然后更改颜色。它在 iOS 升级之前工作得很好,所以我不确定是做了什么更改导致了这个问题:
快速编辑:此外,当我向下滚动表格 View 然后向上滚动时,它会为更多在表格 View Controller 首次加载时未着色的单元格着色(如果这有帮助的话)。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* type=[[self.HandPointer.player_hand objectAtIndex:indexPath.row]cardType];
if ([type isEqualToString:@"ace"]){
cell.backgroundColor = [UIColor colorWithRed:0.81 green:0.91 blue:0.81 alpha:1.0];
}
}
最佳答案
我认为在 tableView: cellForRowAtIndexPath:
方法中进行单元格自定义更好。在这个方法中,
if ([type isEqualToString:@"ace"])
{
cell.backgroundColor = [UIColor aceColor];
}
else // this else is important. If you add this, scrolling works fine.
{
cell.backgroundColor = [UIColor otherCellColor];
}
关于ios - iOS7中更改tableview单元格的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099438/