2013-05-28 86 views
3

enter image description here我有點作爲地圖上的pin註釋並顯示自定義註釋視圖。我的問題是,當我點擊點時,點後面的自定義註釋視圖來自定義註釋視圖而不是顯示在後面它。地圖拼圖中的多個註釋

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    MKAnnotationView *annotationView; 
    PinAnnotationView *pinView = nil; 
    NSString *identifier; 
    if ([annotation isKindOfClass:[DisplayMap class]]) 
    { 
     identifier = @"Pin"; 
     NSInteger myid = ((DisplayMap *)annotation).takeid; 
     MKAnnotationView *pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
     DisplayMap *a = (DisplayMap *)annotation; 
     pinView.annotation=a; 
     if (myid == 1) 
     { 
      UIImage *test = [UIImage imageNamed:@"red_dot.png"]; 
      pinView.image = test; 
      pinView.opaque = NO; 
     } 
     else if (myid == 2) 
     { 
      UIImage *test = [UIImage imageNamed:@"blue_dot.png"]; 
      pinView.image = test; 
      pinView.opaque = NO; 
     } 
     else { 
      UIImage *test = [UIImage imageNamed:@"green_dot.png"]; 
      pinView.image = test; 
      pinView.opaque = NO; 
     } 
    return pinView; 
    } 
    else if ([annotation isKindOfClass:[CalloutAnnotation class]]) 
    { 
     identifier = [NSString stringWithFormat:@"Callout%d",pinView.tag]; 
     annotationView = [[CalloutAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
     CalloutAnnotation *calloutAnnotation = (CalloutAnnotation *)annotation; 
     ((CalloutAnnotationView *)annotationView).title = calloutAnnotation.title; 
     ((CalloutAnnotationView *)annotationView).iTag = calloutAnnotation.iTag; 
     [annotationView setNeedsDisplay]; 
     [UIView animateWithDuration:0.5f 
        animations:^(void) { 
         mapView.centerCoordinate = calloutAnnotation.coordinate; 
        }]; 
     annotationView.annotation = annotation; 
     return annotationView; 
    } 
} 


-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view1 
{ 
    if ([view1.annotation isKindOfClass:[DisplayMap class]]) 
    { 
    DisplayMap *pinAnnotation = ((DisplayMap *)view1.annotation); 
    LoginDetail *obj = [[appDelegate mapArray] objectAtIndex:pinAnnotation.iTag]; 
    [mapView removeAnnotations:annotationRemoveArray]; 

    CalloutAnnotation *calloutAnnotation = [[CalloutAnnotation alloc] init]; 
    calloutAnnotation.title  = pinAnnotation.title; 
    pinAnnotation.calloutAnnotation = calloutAnnotation; 
    [mapView addAnnotation:calloutAnnotation]; 
    [annotationRemoveArray addObject:calloutAnnotation]; 
    [self setzoomonselectannotation:pinAnnotation.coordinate]; 
    } 
} 
+2

請提高的問題 –

+1

發佈一些代碼:( – Rushabh

+0

嘗試刪除所有其他註釋和只顯示當前 –

回答