如何保存所选的MKA注释? [英] How to save the selected MKAnnotation?

查看:111
本文介绍了如何保存所选的MKA注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有mapview的应用程序,它在地图上显示20个引脚(来自Array).当用户单击它时,它可以显示带有右侧附件按钮的气泡. 我的问题来了:我怎么知道哪个针被按下了? 我听到了一些有关mapView:didSelectAnnotationView方法的信息,但是我不太了解如何获取pin/callout索引,以便可以在Array的相同索引处获取对象的信息?感谢您的帮助!

I have an app that has a mapview, and it shows 20 pins (from an Array) on the map. When the user clicks on it, it can show a bubble with a right accessory button. Here come my problem: How do I know which pin was pressed? I heard something about the mapView:didSelectAnnotationView method, but I don't really understand how do you get the pin/callout index, so that I can get the information of the object at the same index of my Array? Thanks for any help!

推荐答案

调用该方法时-由于您的viewController类采用了MKMapViewDelegate,因此您可以在数组上调用-indexOfObject并获取该引脚的索引(注解).假设您的数组中包含注释类类型的对象.

When that method gets called -- because your viewController class has adopted MKMapViewDelegate, you can call -indexOfObject on the array and get the index of that pin (annotation). This is with the assumption that your array holds objects of the kind of annotation class.

- (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];
        }
    }

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

If you need more explanation, we need to know how you are adding those pins, i.e. implementation of - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation.

这篇关于如何保存所选的MKA注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆