0

我有一个奇怪的错误,注释并不总是被添加到我的地图视图中,我添加注释的代码是:

- (void)plotVehicles {

NSMutableArray *currentVehicles = [[MyApplication getInstance] currentVehicles];

for (Vehicle * veh in currentVehicles) {
    VehiclePin * vehiclePin = [[VehiclePin alloc] initWithVehicle:veh];
    [self.mapView addAnnotation:vehiclePin];
    [self.vehiclePins addObject:vehiclePin];
    NSLog(@"current ann %i %@ %@",self.mapView.annotations.count,vehiclePin,self.mapView.annotations);
}
NSLog(@"annotations added %i/%i",self.mapView.annotations.count,self.vehiclePins.count);
}

我正在向mapViewand to添加注释,vehiclePins并且有 2 个日志,第一个(在循环内)显示要添加哪些注释以及 mapview.annotations 的当前状态。此日志的结果是:

current ann 1 <VehiclePin: 0x1573c470> (
    "<VehiclePin: 0x1573c470>"
)

current ann 2 <VehiclePin: 0x9e7f490> (
    "<VehiclePin: 0x1573c470>",
    "<VehiclePin: 0x9e7f490>"
)
 current ann 2 <VehiclePin: 0x9e7f430> (
    "<VehiclePin: 0x1573c470>",
    "<VehiclePin: 0x9e7f490>"
)
current ann 3 <VehiclePin: 0x1573f730> (
    "<VehiclePin: 0x1573c470>",
    "<VehiclePin: 0x9e7f490>",
    "<VehiclePin: 0x1573f730>"
)
 current ann 3 <VehiclePin: 0x1573f870> (
    "<VehiclePin: 0x1573c470>",
    "<VehiclePin: 0x9e7f490>",
    "<VehiclePin: 0x1573f730>"
)
...

总共有 31 个注释,但在该点之后数组从未更改(3 个元素),第二个日志的结果并不那么令人惊讶的是:

annotations added 3/31

我目前正在使用 Xcode 5,使用 xcode 4.6 时没有问题

我错过了什么吗?

编辑:我也检查过CLLocationCoordinate2DIsValid它们是有效的,并且坐标不同。

4

2 回答 2

0

I think the reason is that you are trying to add the same annotation multiple times to the map and to the vehiclePins array.
For the array, this is no problem, since an array can store the same object multiple times. But this is not true for an annotation: Each annotation object is stored only once.

于 2013-10-10T05:37:58.573 回答
0

现在已经修好了。我所做的是卸载应用程序并清理构建,再次编译并开始工作。第二次这种问题发生在我的 XCode 5 上。

于 2013-10-11T02:07:28.300 回答