Iphone 在我滚动地图之前不会显示注释

Iphone 在我滚动地图之前不会显示注释,iphone,objective-c,mkmapview,mkannotation,Iphone,Objective C,Mkmapview,Mkannotation,嗯,我有一个带有地图的视图,在那里我加载了一些注释。一切正常,但当我想删除这些注释并包括其他注释时,它们不会显示,直到我移动(滚动)地图 有什么建议吗 编辑: 似乎不用这个: [self updateMap]; 我必须使用: [self performSelectorOnMainThread:@selector(updateMap) withObject:nil waitUntilDone:true]; 正在更新映射我添加新注释的方法。请尝试以下方法: [mapView removeAnno

嗯,我有一个带有地图的视图,在那里我加载了一些注释。一切正常,但当我想删除这些注释并包括其他注释时,它们不会显示,直到我移动(滚动)地图

有什么建议吗

编辑:

似乎不用这个:

[self updateMap];
我必须使用:

[self performSelectorOnMainThread:@selector(updateMap) withObject:nil waitUntilDone:true];
正在更新映射我添加新注释的方法。

请尝试以下方法:

[mapView removeAnnotations:[mapView annotations]];
NSArray *targetArray = /*YOUR ARRAY NAME with object, containing `latitude`, `longitude` and `title` values*/
for (id *item in targetArray) {
    if (item.latitude && item.longitude) {
        MKPin *pin = [[MKPin alloc] init]; // MKPin is your class which specifies the deledate `MKAnnotation`
        pin.coordinate = CLLocationCoordinate2DMake(item.latitude, item.longitude);
        pin.title = item.title;
        [mapView addAnnotation:pin];
    }
}

在viewdidload中,请使用:

- (void)viewDidLoad 
{

}


希望这有帮助

不,我正在为每个批注使用默认视图,我需要调用
mapView:viewForAnnotation:
方法,但在我滚动MAPI之前不会调用该方法。如果您使用默认视图进行批注,则不必实现
mapView:viewForAnnotation:
方法。此外,如果需要,可以手动运行此方法。在结尾的条件块中写入以下内容:
[self-mapView:mapView-viewForAnnotation:pin]
    NSMutableArray* annotations=[[NSMutableArray alloc] init];
    MyAnnotation* myAnnotation = [[MyAnnotation alloc] init];
myAnnotation.coordinate = theCoordinate;
    [annotations addObject:myAnnotation];
    MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in annotations) 
   {
    NSLog(@"fly to on");
        MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
        MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
        if (MKMapRectIsNull(flyTo)) 
        {
               flyTo = pointRect;
        }
        else
        {
               flyTo = MKMapRectUnion(flyTo, pointRect);
       //NSLog(@"else-%@",annotationPoint.x);
        }
     }

// Position the map so that all overlays and annotations are visible on screen.
mapView.visibleMapRect = flyTo;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                 initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.draggable = NO;
pinView.pinColor=MKPinAnnotationColorGreen;

//button on the right for popup for pins
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;

//zoom button on the left of popup for pins
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[leftButton addTarget:self 
               action:@selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;

UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];


return pinView;