你好,我正在构建一个基于 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/