我有一个奇怪的错误,注释并不总是被添加到我的地图视图中,我添加注释的代码是:
- (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);
}
我正在向mapView
and 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
它们是有效的,并且坐标不同。