leftCalloutAccessoryView图片参考?

时间:2013-08-31 17:33:29

标签: ios mkmapview mapkit mkannotation mkannotationview

您好我正在构建一个基于地图的应用程序,当我点击附件我执行一个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;
}

有人有解决方案获取对图像的引用,以便将此图像发送到详细信息页面吗?

1 个答案:

答案 0 :(得分:2)

您已经使用mapView:annotationView:calloutAccessoryControlTapped:方法参与其中。

创建一个属性以保留对tapped标注中图像的引用:

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

然后您可以随意显示/使用它。