1

在我的 MapView 中有多个 annotationView,每个都有自己的图像,有时当我按下图像时,它会消失并且如果不重新加载 viewController 就永远不会回来。为什么会这样?

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

缺了点什么?

4

2 回答 2

1

你在做什么

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

我还注意到您没有为注释视图设置注释。设置注释视图时,您还应该这样做

annotationView.annotation = annotation;
于 2012-11-09T12:15:08.327 回答
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];
于 2012-12-20T08:06:16.327 回答