Iphone 删除MKAnnotations并将其添加到MapView会给我留下一个空白的MapView
这一问题的后续行动: 从反面视图返回时,我正在呼叫Iphone 删除MKAnnotations并将其添加到MapView会给我留下一个空白的MapView,iphone,mapkit,Iphone,Mapkit,这一问题的后续行动: 从反面视图返回时,我正在呼叫 NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]]; [mapView removeAnnotations:annotations]; 删除地图上的所有图钉(如果这不是最好的方法,请告诉我) 然后: 加上: -(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{ MKPinAnnotationView*an
NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]];
[mapView removeAnnotations:annotations];
删除地图上的所有图钉(如果这不是最好的方法,请告诉我)
然后:
加上:
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“currentloc”];
if([annotation isKindOfClass:[MKUserLocation类]])
返回零;
if([annotation isKindOfClass:[WellPlaceMark class]])
{
...
}
annView.animatesDrop=FALSE;
返回视图;
}
所有这些代码似乎都是在调试器中调用的,但当它完成时,我看到一个空白映射。我试着缩小了,但别针不见了。地图在第一次尝试时加载得很好,但是一旦我调用
removeAnnotations
,它们就再也不会回来了。我发现:我在索引0处添加了一个新的MKMapView
,它出现在我清除的MKMapView
下面。重新使用相同的MKMapView
解决了问题
for(Hole *hole in fetchedObjects)
{
double latitude = [hole.Latitude doubleValue];
cord.latitude = latitude;
double longitude = [hole.Longitude doubleValue];
cord.longitude = longitude;
WellPlaceMark *placemark = [[WellPlaceMark alloc] initWithCoordinate:cord withWellType:[NSString stringWithString: hole.WellType]];
[mapView addAnnotation:placemark];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([annotation isKindOfClass:[WellPlaceMark class]])
{
...
}
annView.animatesDrop=FALSE;
return annView;
}