Objective c 拉刷新应用程序
我是Objective-c的新手,所以我有点困惑,我把它放在我应用程序的另一个部分上,工作得很完美,但是当我在我应用程序的不同视图上使用它时,它会使应用程序崩溃,我很确定我也用同样的方式设置了它 我让Xcode在出错的代码及其最上面一行设置断点Objective c 拉刷新应用程序,objective-c,ios,xcode,Objective C,Ios,Xcode,我是Objective-c的新手,所以我有点困惑,我把它放在我应用程序的另一个部分上,工作得很完美,但是当我在我应用程序的不同视图上使用它时,它会使应用程序崩溃,我很确定我也用同样的方式设置了它 我让Xcode在出错的代码及其最上面一行设置断点 NSArray *timesArray = [self.tableDataArray objectAtIndex:2]; NSDictionary *dictionary = [timesArray objectAtIndex:index
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*TimeArray是停止的,但是没有给出其他错误或任何东西,所以我有点困惑于要更改什么
编辑编号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;
}
)
然后崩溃,出于某种原因,它停止解析
这是自我拉动刷新套件。编辑:
当查询返回的数据不足时(例如,没有下一个总线的可用时间),似乎会发生崩溃。如果您可以确认这一点,那么修复是微不足道的:
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;
}
数组只有一个对象。这是一个您应该以不同方式处理的极端情况吗?Put
NSLog(@“Array:%@”,self.tableDataArray)代码>在错误行之前。它显示了什么?很明显,我想,但是在调用之间,self.tableDataArray
的内容肯定发生了变化。(发布的代码来自cellforrowatinexpath:
,我猜。)看看这个,我不需要所有的信息,我正在填充一个视图,它只显示了接下来3辆公交车的时间,我不知道我做了什么使它循环了那么多次。我只需要《泰晤士报》的一个例子。