ios - leftCalloutAccessoryView 图像引用?

标签 ios mkmapview mapkit mkannotation mkannotationview

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

我的 accessorycontroltapped 代码:

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

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

最佳答案

您已经完成了您的 mapView:annotationView:calloutAccessoryControlTapped: 方法。

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

@property (nonatomic, strong) UIImage *selectedCalloutImage;

并更新委托(delegate)方法:

-(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:方法中将图片传递给后续的controller:

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

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

关于ios - leftCalloutAccessoryView 图像引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18550938/

相关文章:

iphone - 在 ios 中创建自定义注释类时遇到问题

ios - 从 MKMapView 中删除最后添加的注释

ios - Swift - 通过公开按钮将数据从 mapkit 注释传递到另一个 View

ios - 是否可以从 MKPolyline 继承

iphone - MKMapView 在regionDidChangeAnimated 中返回错误的latitudeDelta 和longitudeDelta

ios - 您如何更新 Google 登录以使用新的 Firebase 控制台和 API?

iphone - 在 View Controller 之间切换时自动旋转

ios - 在 Swift 枚举期间从数组中删除?

ios - map 注释的自定义标题

ios - iOS 中的 CURL 请求