【问题标题】:Why when I press the AnnotationView sometime the image disappear?为什么有时我按下 AnnotationView 时图像消失了?
【发布时间】:2012-11-09 12:05:12
【问题描述】:

在我的 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;
    }

缺少什么?

【问题讨论】:

    标签: ios uibutton uiimage mkannotation mkpinannotationview


    【解决方案1】:

    你在做什么吗

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

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

    annotationView.annotation = annotation;
    

    【讨论】:

    • 您能否编辑您的原始帖子以将整个代码包含在 viewForAnnotation 方法中?
    【解决方案2】:

    我换了

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-24
      • 2012-07-10
      • 1970-01-01
      • 2020-05-08
      • 2012-04-21
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多