如何在MKMapView中关闭MKAnnotation的标注 [英] How to close a callout for MKAnnotation in a MKMapView

查看:100
本文介绍了如何在MKMapView中关闭MKAnnotation的标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MKMapView,它有许多注释。选择引脚会显示标注,按下附件会将新的视图控制器弹出到堆栈中。但是,当我从新的VC按回来时,标注仍然是打开的。如何关闭它?

I have a MKMapView that has a number of annotations. Selecting the pin displays the callout and pressing the accessory pops a new viewcontroller onto the stack. However when I press back from that new VC the callout is still open. How do I close it?

我试过了

if([[myMapView selectedAnnotations] count] > 0)
{
    //deselect that annotation
    [myMapView deselectAnnotation:[[myMapView selectedAnnotations] objectAtIndex:0] animated:NO];
}

但这不起作用。 selectedAnnotations在数组中只有一个条目,因此它会进入此语句,但不会关闭callout。

but this does not work. The selectedAnnotations does have a single entry in the array so it does go into this statement but the callout is not closed.

我是否需要在MKAnnotation实现或MKPinAnnotationView中添加内容?

Do I need to add something to my MKAnnotation implementation or my MKPinAnnotationView?

推荐答案

selectedAnnotations中的对象是MKAnnotation的实例

The objects in selectedAnnotations are instances of MKAnnotation

NSArray *selectedAnnotations = mapView.selectedAnnotations;
for(id annotation in selectedAnnotations) {
    [mapView deselectAnnotation:annotation animated:NO];
}

这篇关于如何在MKMapView中关闭MKAnnotation的标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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