开发者

Removing and then adding MKAnnotations to a MapView is leaving me with a blank MapView

开发者 https://www.devze.com 2023-01-01 11:20 出处:网络
A followup to this quesiton: Forcing Reload of View when returning from FlipSideView of Utility Application

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消