拉到刷新崩溃的应用程序

时间:2012-06-21 17:20:47

标签: objective-c ios xcode

我是Objective-c的新手,所以我有点难过,我把它放在我的应用程序的另一部分,并且完美无缺,但当我在我的应用程序的不同视图上使用它时,它会崩溃应用程序,而我我确信我的设置方式相同。

我让Xcode在代码中设置了一个断点,这个代码混乱了这段代码的顶线

    NSArray *timesArray = [self.tableDataArray objectAtIndex:2];
    NSDictionary *dictionary = [timesArray objectAtIndex:indexPath.row];
    cell.timeLabel.text = [dictionary objectForKey:@"time"];
    cell.destinationLabel.text = [dictionary objectForKey:@"destination"];

NSArray * timesArray是什么停留,但没有给出任何其他错误或任何东西,所以我有点难以改变。

编辑编号1: 为清晰起见删除旧编辑。

编辑编号2

好的,所以我再次慢慢检查,结果是它完成了3次完整的数据解析,并输出了我所有的东西。

2012-06-21 13:37:09.148 NextBus[5990:1a603] Array: (
    {
    routeName = "Oxford West";
    routeNumber = 17;
    stopDirection = Westbound;
    stopName = "Griffith At Commissioners Sb";
    stopNumber = 811;
},
"Next 3 Vehicles Arrive At:",
    (
            {
        destination = "To Byron Baseline / Griffith";
        time = "1:58 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:15 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:35 P.M.";
    }
),
"Prediction Last Updated 1:37:06 Pm 6/21/2012"
)
2012-06-21 13:37:09.148 NextBus[5990:1a603] Array: (
    {
    routeName = "Oxford West";
    routeNumber = 17;
    stopDirection = Westbound;
    stopName = "Griffith At Commissioners Sb";
    stopNumber = 811;
},
"Next 3 Vehicles Arrive At:",
    (
            {
        destination = "To Byron Baseline / Griffith";
        time = "1:58 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:15 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:35 P.M.";
    }
),
"Prediction Last Updated 1:37:06 Pm 6/21/2012"
)
2012-06-21 13:37:09.149 NextBus[5990:1a603] Array: (
    {
    routeName = "Oxford West";
    routeNumber = 17;
    stopDirection = Westbound;
    stopName = "Griffith At Commissioners Sb";
    stopNumber = 811;
},
"Next 3 Vehicles Arrive At:",
    (
            {
        destination = "To Byron Baseline / Griffith";
        time = "1:58 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:15 P.M.";
    },
            {
        destination = "To Byron Baseline / Griffith";
        time = "2:35 P.M.";
    }
),
"Prediction Last Updated 1:37:06 Pm 6/21/2012"
)

它什么时候拉我刷它呢

2012-06-21 13:37:45.590 NextBus[5990:1a603] Array: (
    {
    routeName = "Oxford West";
    routeNumber = 17;
    stopDirection = Westbound;
    stopName = "Griffith At Commissioners Sb";
    stopNumber = 811;
}
)

然后崩溃,由于某种原因它停止解析。

这是EGO拉动刷新套件。

1 个答案:

答案 0 :(得分:0)

编辑:

当您的查询返回的数据不足时,例如,当没有时间可用于下一个总线时,似乎会发生崩溃。如果你可以确认这一点,那么修复是微不足道的:

if ([self.tableDataArray count] > 1) {
  NSArray *timesArray = [self.tableDataArray objectAtIndex:2];
  NSDictionary *dictionary = [timesArray objectAtIndex:indexPath.row];
  cell.timeLabel.text = [dictionary objectForKey:@"time"];
  cell.destinationLabel.text = [dictionary objectForKey:@"destination"];
} else {
  //-- do something to show that no times are available
}

您可能正在尝试访问超出其范围的数组:

    NSArray *timesArray = [self.tableDataArray objectAtIndex:2];

timesArray没有3个元素,然后程序崩溃......

您应该查看阵列的填充方式与此操作的期望值。

编辑:

根据您对问题所做的编辑,似乎您执行了几次发布的行,并且只是程序崩溃的最后一次。如您所见,在前几次迭代中,您的数组中填充了足够的元素;在最后一种情况下:

2012-06-21 13:25:03.448 NextBus[5964:1a603] Array: (
{
routeName = Springbank;
routeNumber = 5;
stopDirection = Eastbound;
stopName = "Berkshire At Berkshire Place Sb";
stopNumber = 2196;
}

数组只有一个对象。这是一个你应该采用不同处理方式的角落吗?