代码之家  ›  专栏  ›  技术社区  ›  ddnl

leftCalloutAccessoryView图像引用?

  •  0
  • ddnl  · 技术社区  · 12 年前

    您好,我正在构建一个基于地图的应用程序。当我点击附件时,我会执行一个分段到一个个人资料页面,该页面会提供有关引脚位置的信息。现在,我在LeftCalloutAccesoryView中有一个图像,我想在详细信息页面上显示它。现在我很好奇是否有一种方法可以获得LeftCalloutAccesoryView上设置的图像。我动态添加图像。

    我的accessorycontroltaped代码:

    -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
    calloutAccessoryControlTapped:(UIControl *)control
    {
        companytitle = view.annotation.title;
        description = view.annotation.subtitle;
        thumbprofileimage = view.image;
        //thumbprofileimage = [(UIImageView *)view.leftCalloutAccessoryView setImage:pin.image];
        //UIImageView *leftIconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        //leftIconView = [view.leftCalloutAccessoryView [[UIImageView alloc]];
        //view.leftCalloutAccessoryView;
        [self performSegueWithIdentifier:@"showPlattegrondDetails" sender:self];
    }
    

    我的固定引脚代码:

    - (MKAnnotationView *)mapView:(MKMapView *)mpView viewForAnnotation:(id <MKAnnotation>)annotation {
    
        static NSString *identifier = @"MyLocation";
    
        if ([annotation isKindOfClass:[RouteAnnotation class]]) {
    
            MKPinAnnotationView *annotationView =
            (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    
            if (annotationView == nil) {
                annotationView = [[MKPinAnnotationView alloc]
                                  initWithAnnotation:annotation
                                  reuseIdentifier:identifier];
            } else {
                annotationView.annotation = annotation;
            }
    
            annotationView.enabled = YES;
            annotationView.canShowCallout = YES;
    
            leftIconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
            [leftIconView setImage:pin.image];
            annotationView.leftCalloutAccessoryView = leftIconView;
            //annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    
            UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            annotationView.rightCalloutAccessoryView = rightButton;
    
            return annotationView;
        }
        return nil;
    }
    

    有人有办法获得图片的参考,这样我就可以将此图片发送到详细信息页面吗?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Steve Wilford    12 年前

    你已经离开了 mapView:annotationView:calloutAccessoryControlTapped: 方法

    创建一个特性以保留对轻敲详图索引中图像的引用:

    @property (nonatomic, strong) UIImage *selectedCalloutImage;
    

    并更新委托方法:

    -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
    calloutAccessoryControlTapped:(UIControl *)control
    {
        companytitle = view.annotation.title;
        description = view.annotation.subtitle;
        thumbprofileimage = view.image;
        //thumbprofileimage = [(UIImageView *)view.leftCalloutAccessoryView setImage:pin.image];
        //UIImageView *leftIconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        //leftIconView = [view.leftCalloutAccessoryView [[UIImageView alloc]];
        //view.leftCalloutAccessoryView;
    
        // Keep a reference to the callout's image
        self.selectedCalloutImage = [(UIImageView *)view.leftCalloutAccessoryView image];
    
        [self performSegueWithIdentifier:@"showPlattegrondDetails" sender:self];
    }
    

    然后将图像传递给中的后续控制器 prepareForSegue:sender: 方法:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"showPlattegrondDetails"])
        {
            DetailViewController *controller = segue.destinationViewController;
            controller.image = self.selectedCalloutImage;
        }
    }
    

    然后,您可以随心所欲地显示/使用它。

    推荐文章