0

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

我的附件控制窃听代码:

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

是否有人有获取图像参考的解决方案,以便我可以将此图像发送到详细信息页面?

4

1 回答 1

2

你已经用你的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;
    }
}

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

于 2013-08-31T19:01:36.943 回答