2012-11-09 54 views
1

在我的MapView中有多個annotationView,每個都有自己的圖像,有時候當我按下圖像時,它會消失,如果不重新加載viewController,它將不會再回來。爲什麼會發生?爲什麼當我按下AnnotationView有時圖像消失?

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id 
    <MKAnnotation>)annotation 
    { 
     if ([annotation isKindOfClass:[AnnotationView class]]) { 

       return nil; 
     } 

     if ([annotation isKindOfClass:[AnnotationCustom class]]){ 


      static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 

      MKPinAnnotationView *annotationView = (MKPinAnnotationView*) [mapView 
        dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 

      annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 

          reuseIdentifier:AnnotationIdentifier]; 

     if ([self.nameTable isEqualToString:@"Movies"]){ 
      if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){ 

        annotationView.image = [UIImage imageNamed:@"iphone_movies.png"]; 


      }else{ 
        annotationView.image = [UIImage imageNamed:@"ipad_movies.png"]; 

      } 


    }else if ([self.nameTable isEqualToString:@"Food_Drink"]){ 
      if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){ 
       annotationView.image = [UIImage imageNamed:@"iphone_foodDrink.png"]; 


      }else{ 
       annotationView.image = [UIImage imageNamed:@"ipad_foodDrink.png"]; 


      } 
    }else if (......){ 
       //same procedure for all annotationView 

    } 


    UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    annotationView.rightCalloutAccessoryView=detailButton; 

    annotationView.canShowCallout = YES; 
    annotationView.draggable = YES; 

    return annotationView; 
    } 

東西不見了?

回答

0

我更換

MKPinAnnotationView *annotationView = (MKPinAnnotationView*) [mapView 
       dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 

annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
reuseIdentifier:AnnotationIdentifier]; 

MKAnnotationView *annotationView = (MKAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 
    annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 
1

您在

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 

我也注意到你沒有設置註解視圖註釋做任何事情。當設置了一個註解視圖,你也應該做

annotationView.annotation = annotation; 
+0

它仍然發生 –

+0

能否請您編輯您原來的職位,包括在整個代碼viewForAnnotation方法? – NikosM

相關問題