iphone在MapView中检测选择的MKPinAnnotation

Pan*_*nos 0 iphone mkmapview mkannotation mkannotationview ios4

我有一个自定义的MKPinAnnotation,其中我添加了几个peroperties,如对象的Id和类型.我想要的是当有人在MapView中选择一个引脚来检测选择了哪个引脚并获取该数据时.

并在其视图上显示一个按钮,以便在按钮的操作中使用该数据.

有人能帮忙吗?我找不到如何检测是否(和哪个)注释被选中.

Vik*_*ngs 5

已经有一种内置的方法来处理这种情况.您需要使用以下方法.view.annotation是被点击的注释.

- (void)mapView:(MKMapView *)mapView 
 annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"The annotation tapped is: %@", view.annotation.title);
}
Run Code Online (Sandbox Code Playgroud)

编辑:可以在这里找到,API是你的朋友.

https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/doc/uid/TP40008204