iOS 6表格滚动导致问题

时间:2013-03-02 03:10:15

标签: uitableview ios6 uiscrollview

我的表视图中有两个部分,一个用于测试状态,另一个用于结果。

第一部分的第三行在测试完成后会发生变化。在测试过程中,它会记录完成百分比,并在更改后显示是否已检测到任何问题。

文本的颜色也会改变,表示不好/好/好。对于这个特定的测试,大约有20行结果。

问题在于,在这20个结果中,两个细胞被处理为第一部分中的第三个细胞并变为红色。

现在我假设我滚动表重新加载,这必然意味着我的代码不正确,并且只有通过大量结果的测试显示。任何帮助都会很棒。我怀疑它是下面的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *serverLoc = [tableView dequeueReusableCellWithIdentifier:@"speedCell"];
    //   UITableViewCell *switchCell = [tableView dequeueReusableCellWithIdentifier:@"switchCell"];

    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    serverLoc.textLabel.text = @"Test location:";
                    serverLoc.detailTextLabel.text = testLocation;
                    serverLoc.selectionStyle = UITableViewCellSelectionStyleNone;
                    serverLoc.userInteractionEnabled = NO;
                    break;
                case 1:
                    serverLoc.textLabel.text = @"Status:";
                    serverLoc.detailTextLabel.text = statusText;
                    serverLoc.selectionStyle = UITableViewCellSelectionStyleNone;
                    serverLoc.userInteractionEnabled = NO;
                    break;
                case 2:
                    if ([TestEnded isEqualToString:@"no"]) {
                        serverLoc.textLabel.text = @"Progress";
                        serverLoc.selectionStyle = UITableViewCellSelectionStyleNone;
                        serverLoc.userInteractionEnabled = NO;
                        serverLoc.detailTextLabel.text = [NSString stringWithFormat:@"%ld%%", (long)progressInt];
                        break;
                    }
                    else {

                        serverLoc.selectionStyle = UITableViewCellSelectionStyleBlue;
                        serverLoc.userInteractionEnabled = YES;
                        serverLoc.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                        serverLoc.textLabel.text = @"Problems Detected:";
                        serverLoc.detailTextLabel.text = [NSString stringWithFormat:@"%ld", (long)problemsDetected];

                        if (problemsDetected == 0) {
                            serverLoc.textLabel.textColor = [UIColor colorWithRed:0.0 / 255 green:102.0 / 255 blue:51.0 / 255 alpha:1.0];
                            serverLoc.detailTextLabel.textColor = [UIColor colorWithRed:0.0 / 255 green:102.0 / 255 blue:51.0 / 255 alpha:1.0];
                        }
                        else if (problemsDetected == 1) {
                            serverLoc.textLabel.textColor = [UIColor colorWithRed:226.0 / 255 green:232.0 / 255 blue:52.0 / 255 alpha:1.0];
                            serverLoc.detailTextLabel.textColor = [UIColor colorWithRed:226.0 / 255 green:232.0 / 255 blue:52.0 / 255 alpha:1.0];
                        }
                        else {
                            serverLoc.textLabel.textColor = [UIColor redColor];
                            serverLoc.detailTextLabel.textColor = [UIColor redColor];
                        }

                    }
                    break;    
            }
            break;

我不确定它是否会在我第一次实施时起作用。它“确实”但显然我不需要滚动到足以揭开错误。

提前感谢任何指针

1 个答案:

答案 0 :(得分:1)

这里的代码看起来很好......听起来你的表正在重复使用为这个特定路径设置的单元格,但是在重用单元格之前没有将值返回到默认值。 (例如,在= = 1的情况下:severLoc.textLabel.textColor = [UIColor blackColor];)如果情况0,0和0,1在抓取重用的单元格时最终得到0,2单元,也会显示。