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

查看:171
本文介绍了具有一定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 == YES),这些你可以设置addedByUser为true。

. 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天全站免登陆