A followup to this quesiton:
Forcing Reload of View when returning from FlipSideView of Utility Application
When returning from the flipside view, I'm calling
NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]];
[mapView removeAnnotations:annotations];
To remove all the pins from the map (let me know if this isn't the best way to do this).
Then:
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];
}
Plus:开发者_JAVA百科
- (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;
}
All of this code seems to be called in the debugger, but when it's finished, I'm presented with a blank map. I've tried zooming out and the pins are nowhere. The map loads up fine on the first try, but once I call removeAnnotations
, they never return.
I figured it out: I was adding a new MKMapView
at index 0, which was appearing underneath the MKMapView
I had cleared. Re-using the same MKMapView
solved the problem.
精彩评论