实际上,我正在我的应用程序中开发一些东西,它可以在我的 MKMapView
中显示注释这些注释应该是可单击的并将参数传递给方法。
现在的问题是如何在点击披露按钮时将参数传递给下一个函数。
对于注释的格式,我使用 - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
显示公开按钮的方法。但问题是,如何从 Annotation
中获取值当前显示的对象是什么?
我的代码为Annotation
(仅相关部分):
@synthesize coordinate, id, title, subtitle;
+ (id)annotationWithCoordinate:(CLLocationCoordinate2D)coordinate {
return [[[[self class] alloc] initWithCoordinate:coordinate] autorelease];
}
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
self = [super init];
if(nil != self) {
self.coordinate = coordinate;
}
return self;
}
当触摸公开按钮时,方法- (void)displayInfo:(NSNumber *) anId;
应该在移交时调用 Annotation.id
作为anId
参数。
披露按钮是使用该代码生成的:
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
dropPin.rightCalloutAccessoryView = disclosureButton;
dropPin.animatesDrop = YES;
dropPin.canShowCallout = YES;
所以 - 问题:
我如何将该参数传递给函数或读取 id
点击的Annotation
?
我认为我可以使用 UIButton 的选择器(但是 - 如何传递 id?)或使用 - (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
来处理 discoveryButton 上的点击。 (再次 - 如何传递 id?)。
我希望您明白我的意思,非常感谢您的回答! :)
最佳答案
在 calloutAccessoryControlTapped 中,注释可通过 View 获得:
MKAnnotation *annotation = view.annotation;
关于iphone - MKAnnotationView 并将数据传递给另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4509663/