我知道这是一个重复的问题,但我没有得到这个问题的解决方案。
我正在使用一个表格视图,我想根据一些状态表单 web 服务更改一个文本标签的颜色。
但问题是当表格视图上下滚动时,每个文本标签的颜色都会发生变化。这是我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [[self.Contents objectAtIndex:indexPath.row]event];
if([[[self.Contents objectAtIndex:indexPath.row]status] isEqualToString:@"Failed"]){
cell.textLabel.textColor = [UIColor redColor];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
当cell ==nil
条件被评论时,它工作正常。但我知道这不是做到这一点的确切方法。
谁能帮我解决这个问题。提前致谢。