-2

我有一个 UITableview 和 UICutsom 单元格。在那个 UITableview 中,我使用 Web 服务填充数据。我更改单元格的背景颜色和字体颜色。当我向上和向下滚动该 Tableview 单元格背景颜色和标签颜色时,其他单元格也会发生变化。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"FieldInventoryCell";

    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    FieldInventoryCell *cell=(FieldInventoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {

        NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"FieldInventoryCell" owner:self options:nil];

        cell=[nib objectAtIndex:0];
    }

    NSArray *ar = [[arr objectAtIndex:indexPath.row]componentsSeparatedByString:@"|"];
    cell.Status.text=[ar objectAtIndex:1];
    cell.serialnumber.text=[ar objectAtIndex:0];
    cell.date.text=[ar objectAtIndex:2];

    if([cell.serialnumber.text isEqualToString:@"Grand Total"])
    {

       cell.contentView.backgroundColor=[UIColor blueColor];
        cell.serialnumber.textColor=[UIColor whiteColor];

    }
     if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"])
    {
        //cell.contentView.backgroundColor=[UIColor blueColor];
        cell.serialnumber.textColor=[UIColor orangeColor];

    }


    return cell;

}
4

1 回答 1

0

据我从您的帖子中了解到,您可能遇到的问题与出队单元有关。您正在为 contentView 和序列号标签设置一些颜色,但如果不满足条件,则不会重置它们。由于表格重复使用单元格,因此您已经着色的项目将出现在新元素中。要修改问题,请将颜色重置为默认值,即类似

// ...
if([cell.serialnumber.text isEqualToString:@"Grand Total"])
{

    cell.contentView.backgroundColor=[UIColor blueColor];
    cell.serialnumber.textColor=[UIColor whiteColor];

} else {
    // reset color
    cell.contentView.backgroundColor=[UIColor clearColor];
    cell.serialnumber.textColor=[UIColor blackColor];
}

if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"])
{
    //cell.contentView.backgroundColor=[UIColor blueColor];
    cell.serialnumber.textColor=[UIColor orangeColor];

} else {
    // reset color
    cell.serialnumber.textColor=[UIColor blackColor];
}
于 2013-10-16T13:01:55.223 回答