iOS 6表格滚动导致问题 [英] iOS 6 table scrolling causing issues

查看:80
本文介绍了iOS 6表格滚动导致问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

There are two sections in my table view, one for test status and one for results.

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

The third row in the first section gets changed upon the test completing. During the test it documents the percentage complete and after it changes to showing if any problems have been detected.

文本的颜色也会更改以指示错误/确定/良好。对于这个特定的测试,大约有20行结果。

The color of the text also changes to indicate bad/ok/good. For this particular test there are about 20 rows of results.

问题是,在这20个结果中,两个单元格被视为第一部分中的第三个单元格并变为红色。

The problem being that within those 20 results two cells are being treated like the third cell in section one and turning red.

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

Now I assume as I scroll the table reloads which must mean my code is incorrect and has only be shown up by a test with lots of results. Any help would be great. I suspect it is the code below:

- (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;

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

I wasn't sure if it would work when I first implemented it. It "did" but clearly I wasn't needing to scroll enough to unveil the bug.

提前感谢任何指针

推荐答案

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

The code here looks fine... It sounds like your table is reusing the cell set up for this particular path but not returning the values to default before reusing the cell. (e.g. in the section == 1 case: severLoc.textLabel.textColor = [UIColor blackColor];) This will also show up if case 0,0 and 0,1 end up with a 0,2 cell when grabbing a reused cell.

这篇关于iOS 6表格滚动导致问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆