NSMutable 数组错误 & showAnnotations

NSMutable array error & showAnnotations

提问人:Tricodoro 提问时间:3/3/2014 最后编辑:Tricodoro 更新时间:3/16/2014 访问量:117

问:

我有以下情况。我开发了一个应用程序,可以经常检索 POI 的值,我想在地图上显示为注释。为此,我编写了以下方法,在检索到一组新的 POI 后调用:

-(void)showAnnotation{

[self removeAllPinsButUserLocation];

annotationArray = [[NSMutableArray alloc] init];

for (Poi *poi in [parser.pois allValues]) {

    myAnnotation *arr = [[myAnnotation alloc] init];
    arr.title = [NSString stringWithFormat:@"%@ (%@)",poi.description, sensor.name];
    arr.subtitle = [NSString stringWithFormat:@"%@, %@ %@",poi.street, poi.postalcode, poi.city];
    arr.coordinate = CLLocationCoordinate2DMake(poi.lattitude, poi.longitude);

    [annotationArray addObject:arr];

    arr = nil;
}

[self.mapView addAnnotations:annotationArray];
[self.mapView showAnnotations:annotationArray animated:NO];

}

问题是我收到一个错误(由于未捕获的异常“NSGenericException”而终止应用程序,原因:“* 集合<__NSArrayM:0x14ebe9b0>在枚举时发生了突变。

但是,仅当我在最后一行中设置 animated:NO,而不是设置为 animated:YES 时......

有人对此有答案吗?

感谢您的回复!

Eelco公司

目标-C 阵 列 附注 可变

评论

0赞 3/14/2014
这个方法从哪里调用?是否确定在此方法循环访问值未被检索(修改)?应用是在计时器上检索 POI 还是通过某些用户操作检索 POI?parser.pois
0赞 Tricodoro 3/16/2014
@Anna:在 XMLParser 对象中,在 parserDidEndDocument 方法中,我调用 showAnnotation 方法。所以在我看来,这应该是不可能的。此外,在 iOS 模拟器中没有发生错误,仅在我的 iPhone 上......
0赞 3/16/2014
在真实设备上的执行速度可能稍慢,它可能具有不同的 iOS 版本等,这都可能导致在代码中暴露问题,其中它依赖于在某个特定时间段内以特定顺序发生的特定事情。也许您的解析正在再次启动,而 showAnnotation 仍在运行。您必须使用 NSLogs、断点对真实设备进行一些调试。也许 parserDidEndDocument 是一个太低级的方法,从中不知道可以开始这个“耗时”的显示注释的过程。
0赞 Tricodoro 3/18/2014
谢谢你的想法!我也是这么想的,所以我已经开始重新编码一些方法,并将在解析完成后使用通知中心开始显示注释。我希望这在设备本身上效果更好。

答: 暂无答案