Ios UITableView-电池在初始负载时未着色?

Ios UITableView-电池在初始负载时未着色?,ios,objective-c,Ios,Objective C,我正在VC中实现UITableViewDelegate和UITableViewDataSource 我有以下代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { // do stuff if(condition){ cell.textLabel.backgroundColor = [UIC

我正在VC中实现
UITableViewDelegate
UITableViewDataSource

我有以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
    (NSIndexPath *) indexPath {
    // do stuff 
    if(condition){
        cell.textLabel.backgroundColor = [UIColor redColor];
    }
    else {
        cell.textLabel.backgroundColor = [UIColor blackColor];
    }
}
相当标准的东西。我遇到的问题是第一组可见细胞没有颜色。如果我滚动到不可见的单元格,我会得到颜色正确的单元格。如果我向后滚动,我会看到单元格是彩色的

我知道单元格是根据需要“创建”和“销毁”的,这就解释了其中的一些原因,我只是不明白为什么在我看到任何东西之前触发的
cellforrowatinexpath
我的着色条件被命中,会导致。。。没有颜色

一种解决方法是在调用表视图上的
reloadData
后遍历可见单元格,我只是希望有一种更简单的方法


Dane

单元格着色需要在
tableView:willDisplayCell:ForRowatineXpath:
委托方法中进行,而不是在
tableView:CellForRowatineXpath:
方法中进行


tableView:cellForRowAtIndexPath:
方法中删除任何单元格着色逻辑,并将其移动到
tableView:willDisplayCell:forRowAtIndexPath:
方法中。

您将该条件置于何处?