iphone - 如何在 MKMapView 中关闭 MKAnnotation 的标注

标签 iphone objective-c

我有一个 MKMapView,它有很多注释。选择图钉显示标注并按下附件将新的 View Controller 弹出到堆栈上。但是,当我从那个新的 VC 中按回时,标注仍然打开。如何关闭它?

我试过了

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

但这行不通。 selectedAnnotations 在数组中确实有一个条目,所以它确实进入了这个语句,但标注没有关闭。

我是否需要向我的 MKAnnotation 实现或我的 MKPinAnnotationView 添加一些内容?

最佳答案

selectedAnnotations中的对象是MKAnnotation的实例

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

关于iphone - 如何在 MKMapView 中关闭 MKAnnotation 的标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1193928/

相关文章:

iphone - iOS14 Exchange Online共享邮箱

ios - 如何获取有关月份和年份的数据

objective-c - 使用typedef枚举时,返回类型枚举EnumName返回枚举成员时会产生编译器错误

iphone - UIScrollView 在模拟器中过来 UIImage

ios - 如何在 C 函数中触发 NSTimer

iphone - 正在引用的 SQLite 空数据库

iphone - OpenAL 的音效库/扩展(在 iOS 上运行)?

iphone - iphone 和 android 的 sip 堆栈

objective-c - iOS : is there a way to use a single class to hold common variables and not break Object Oriented principles?

ios - [NSConcreteValue浮点值] : unrecognized selector sent to instance