在我的应用程序中,我有一个使用 UILongPressGestureRecognizer 放置图钉的 mapView。当屏幕被按下时,坐标被地理编码并且一个大头针被放下,并且地址被设置为标题。屏幕上会有多个引脚,注释视图有一个标注附件,它将另一个控制器(称为 PinViewController)推到堆栈上。PinViewController 有一个标签,我想显示图钉的标题。
这是删除引脚的代码:
-(void)press:(UILongPressGestureRecognizer *)recognizer
{
CGPoint touchPoint = [recognizer locationInView:worldView];
CLLocationCoordinate2D touchMapCoordinate = [worldView convertPoint:touchPoint toCoordinateFromView:worldView];
geocoder = [[CLGeocoder alloc]init];
CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate
altitude:CLLocationDistanceMax
horizontalAccuracy:kCLLocationAccuracyBest
verticalAccuracy:kCLLocationAccuracyBest
timestamp:[NSDate date]];
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocoder:completionHandler: called");
if (error) {
NSLog(@"Geocoder failed with error: %@", error);
} else {
CLPlacemark *place = [placemarks objectAtIndex:0];
geocodedAddress = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]];
if (UIGestureRecognizerStateBegan == [recognizer state]) {
addressPin = [[MapPoint alloc]initWithAddress:geocodedAddress coordinate:touchMapCoordinate
title:geocodedAddress];
[worldView addAnnotation:addressPin];
}
}
}];
}
这是 PinViewController 被推送到堆栈的代码:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
PinViewController *pinViewController = [[PinViewController alloc]init];
[[self navigationController]pushViewController:pinViewController animated:YES];
pinViewController.label.text = addressPin.title;
}
我遇到的问题是标签只显示要进行地理编码的最后一个地址。因此,当我放下一个引脚并按下标注附件按钮时,正确的地址被推送到 PinViewController。但是如果我按下另一个注解的标注附件按钮,最后一个引脚的地址会被推送到 PinViewController。所以我需要找到一种方法,以便当我按下注解视图的标注附件按钮时,将注解的标题传递给 PinViewController。我真的很感激一些帮助。