2010-05-31 64 views
0

後隨該quesiton:刪除,然後添加MKAnnotations到MapView的離開了我一個空白的MapView

Forcing Reload of View when returning from FlipSideView of Utility Application

當從另一面視圖返回,我打電話

NSArray *annotations = [NSArray arrayWithArray:[mapView annotations]]; 
[mapView removeAnnotations:annotations]; 

要從地圖上刪除所有的針腳(讓我知道這是不是這樣做的最佳方式)。

然後:

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; 
} 

所有這些代碼似乎在調試器中調用,但它結束時,我看到一個空白的地圖。我嘗試縮小和引腳無處。第一次嘗試的地圖加載得很好,但一旦我打電話給removeAnnotations,他們就再也沒有回來。

回答

0

我想到了:我在索引0處添加了一個新的MKMapView,該索引出現在已清除的MKMapView的下方。重新使用相同的MKMapView解決了這個問題。