如何更改表视图上的颜色备用单元格

Pri*_*ka 5 iphone

我想在数据库中显示表视图单元格的数据,所以我想根据第一个单元格灰色的数据方式给单元格颜色然后再下一个棕色的单元格我想要显示灰色单元格,所以任何人都可以告诉我什么是最简单的程序.

先生和问候,Priyanka.

5hr*_*hrp 1

如果您指的是单元格的背景颜色,则更改它的最简单方法:

cell.backgroundView.backgroundColor = [UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)

看起来像:

- (UITableViewCell *) tableView:tableView cellForRowAtIndexPath:indexPath
{
    cell = ... // dequeue or initialize cell
    switch (criteriaFromDatabase) 
    {            
        case 0:
            cell.backgroundView.backgroundColor = [UIColor greenColor];
            break;
        case 1:
            cell.backgroundView.backgroundColor = [UIColor blueColor];
            break;
        default:
            cell.backgroundView.backgroundColor = [UIColor redColor];
            break;
    }
    return cell;
}
Run Code Online (Sandbox Code Playgroud)