ios - iOS7中更改tableview单元格的背景颜色

标签 ios uitableview ios7

自从升级到 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/

相关文章:

ios - Apple itunes 应用程序链接在 UIWebView 而不是 App Store 中打开

ios - 动画 block 在更新文本后重置为原始位置

iphone - 如何在 iOS 7 中强制相机拍摄方形照片

ios - 如何检查UITableViewCellAccessoryDe​​tailButton的可用性?

ios - 如何防止 WKWebView 重复请求访问位置的权限?

ios - iOS 中缓慢的默认访问崩溃

ios - Alamofire:如何在 UITableView 中顺序下载 zip 文件

swift - 自定义 UITableViewCell 中的 UIView 在滚动时重绘

swift - 单击 tvos 应用程序中 TableView 单元格内的 Collection View 单元格

iphone - MKMapView setRegion :animated: animation is going really slow on iOS7