删除具有特定 pinColor 的 MKMapView 注释? [英] Remove MKMapView Annotations with a certain pinColor?

查看:29
本文介绍了删除具有特定 pinColor 的 MKMapView 注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以删除给定 pinColor 的给定 MKMapView 上的所有注释?在为我的应用程序的一部分显示新注释之前,我试图清除我地图上所有用户输入的注释(图钉),但我不知道在有选择地删除注释时我可以做到多细化...

Is it possible to remove all annotations on a given MKMapView of a given pinColor? I'm trying to clear all user-entered annotations (pins) on my map before displaying new ones for a part of my app, but I didn't know how granular I can be in selectively removing annotations...

我只想删除所有具有 MKPinAnnotationColorGreen(绿色)引脚的注释,但我也可以简单地删除用户输入的所有引脚,如果有办法可以跟踪它们.

I'd like to just remove all annotations that have MKPinAnnotationColorGreen (green) pins, but I'd also be able to simply remove all pins entered by the user, if there's a way I could track those.

我知道我可以简单地做:

I know I could simply do:

[myMapView removeAnnotations:myMapView.annotations];

...然后重新绘制我想要的所有注释,但这似乎是在浪费资源.

... then redraw all the annotations I want, but that seems like a waste of resources.

有什么建议吗?

推荐答案

我现在无法测试,但您是否尝试过:

I am not able to test this right now, but have you tried:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pinColor == %d",  MKPinAnnotationColorGreen];
[myMapView removeAnnotations:[myMapView.annotations filteredArrayUsingPredicate:predicate]];

至于用户添加的,您可能需要自己跟踪.您还可以创建自己的 MKPinAnnotation 子类.在该子类上,添加属性

As for the ones added by the user, you might need to keep track of those yourself. You could also create your own subclass of MKPinAnnotation. On that subclass, add the property

@property (nonatomic, BOOL) addedByUser;

.如果它们是由用户添加的,您可以将 addedByUser 设置为 true,然后使用上述类似方法过滤掉那些(例如@" addedByUser == YES").

. You could set addedByUser to true if they were added by the user and then filter out those using a similar approach above (eg. @"addedByUser == YES").

这篇关于删除具有特定 pinColor 的 MKMapView 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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