简体   繁体   English

如何从另一个类中删除mapview注释

[英]How to remove mapview annotation from another class

I have a MKMapView with lots of annotations. 我有一个带有很多注释的MKMapView When I tap on an annotation, the contact details( ABPersonViewController ) of the annotation is pushed. 当我点击注释时, ABPersonViewController注释的联系人详细信息( ABPersonViewController )。 In this class I have an option to delete the contact. 在此类中,我可以选择删除联系人。 As the contact is deleted from the addressbook, at the same time I need to remove the annotation from the mapview too. 由于联系人已从通讯录中删除,因此同时我也需要从mapview中删除注释。

As the delete button is tapped, the contact is removed from the addressbook, and the ABPersonViewController class is popped from the navigation stack. 点击删除按钮后,联系人将从通讯簿中删除,并且ABPersonViewController类从导航堆栈中弹出。 Now the user sees the mapview. 现在,用户可以看到地图视图。 But it should be without the annotation(contact) which was removed. 但是应该没有被删除的注释(联系人)。 How can I do this. 我怎样才能做到这一点。

Add all the annotations in a mutable array and their corresponding address with it like: 将所有注释添加到可变数组及其对应的地址中,如下所示:

NSMutablearray *array; NSMutablearray *数组;

[array add object:[NSDictionary dictionarywithobjectandkeys:@"your object and keys"]; [数组添加对象:[带有对象和键的NSDictionary词典:@“您的对象和键”];

Now when the user deletes the address its subsequent annotation will also be deleted. 现在,当用户删除地址时,其后续注释也将被删除。 That should do it. 那应该做。

Get the annotations from the mapview using the annotation property. 使用annotation属性从地图视图中获取annotation Then iterate through the annotation list to get the particular annotation then use the 然后遍历注释列表以获取特定注释,然后使用

- (void)removeAnnotation:(id < MKAnnotation >)annotation

method to remove the annotation. 删除注释的方法。 I hope it will take care of your problem. 希望它能解决您的问题。

要删除所有注释,请使用以下代码;

[mapView removeAnnotations:mapView.annotations]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM