确定选择了哪个MKPinAnnotationView? [英] Determine which MKPinAnnotationView was selected?
问题描述
我在地图上放置了一些自定义MKPinAnnotationView,其中包含有关地标的不同信息(名称,描述,图像,附件按钮).当用户单击并打开其中的一个针脚,然后单击其中的附件按钮时,我想知道用户单击了哪个针脚,以便为视图控制器加载更详细的信息.
I place some custom MKPinAnnotationView on the map, with different information about landmarks (name, description, image, accessory button). When a user click and open one of the pins, and then click the accessory button inside it, I want to know which of the pins the user have clicked so I can load a viewcontroller with more detailed information.
我发现了这些方法:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
}
...但是我怎么知道选择了哪个引脚?我想做类似的事情:
... but how do I know which pin was selected? I would like to do something like:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
//Example
if ([view.description isEqualToString: @"Golden Gate"])
{
//Load golden gate information in a new viewcontroller
}
}
...但是view.description不会给我正确的信息.
...but view.description won't give me the right information.
预先感谢
推荐答案
如果将名称/描述存储在MKAnnotationView
的title
/subtitle
中,则只需访问以下信息即可访问这些信息
If you're storing the name/description in the title
/subtitle
of your MKAnnotationView
you can access these informations just by accessing to the annotation
property of the MKAnnotationView
:
if ([view.annotation.title isEqualToString: @"Golden Gate"])
{
//Load golden gate information in a new viewcontroller
}
这篇关于确定选择了哪个MKPinAnnotationView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!