如何保存选定的MKAnnotation?

Rob*_*yan 3 mkmapview callouts mkannotation ios xcode4.2

我有一个有mapview的应用程序,它在地图上显示20个引脚(来自数组).当用户点击它时,它可以显示带有正确附件按钮的气泡.这就是我的问题:我怎么知道哪个引脚被按下了?我听说过mapView:didSelectAnnotationView方法的一些内容,但我真的不明白你如何得到pin/callout索引,以便我可以在我的Array的同一索引处获取对象的信息?谢谢你的帮助!

Can*_*pus 6

调用该方法时 - 因为您的viewController类已采用MKMapViewDelegate,您可以调用-indexOfObject该数组并获取该引脚的索引(注释).这是假设您的数组包含那种注释类的对象.

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
        // Annotation is your custom class that holds information about the annotation
        if ([view.annotation isKindOfClass:[Annotation class]]) {
            Annotation *annot = view.annotation;
            NSInteger index = [self.arrayOfAnnotations indexOfObject:annot];
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果您需要更多解释,我们需要知道您是如何添加这些引脚的,即实现- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation.