如何删除某个注释图钉

发布于 2024-11-18 06:00:53 字数 376 浏览 1 评论 0原文

我有一个应用程序,可以向地图视图添加注释点,如下所示:

annot = [[AnnotationDelegate alloc] init];
annot.coordinate = CLLocationCoordinate2DMake(lat,long);
annot.title = [NSString stringWithFormat:@"%d",id];
annot.subtitle = string;
[mapView addAnnotation: annot]; 

该代码块可以执行多次,因为我允许用户向地图视图添加任意数量的引脚。我的问题是,是否有办法修改它以便用户可以删除某个引脚?现在我似乎只能删除最近添加的一个。

希望有任何帮助,谢谢。

I've got an application that adds annotation points to a mapView like so:

annot = [[AnnotationDelegate alloc] init];
annot.coordinate = CLLocationCoordinate2DMake(lat,long);
annot.title = [NSString stringWithFormat:@"%d",id];
annot.subtitle = string;
[mapView addAnnotation: annot]; 

This block of code can be executed several times, as I allow the user to add as many pins as they'd like to the mapView. My question is, would there be a way to modify this so that the user could REMOVE a certain pin? Right now I can only seem to remove the one most recently added.

Would appreciate any help, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花肆意 2024-11-25 06:00:53

只需使用以下命令删除注释

[mapView removeAnnotation:annotationToRemove]

即可:假设您有某种形式的 UI 来使用户能够选择他们正在处理的用户界面?例如,您可能会遇到这样的场景:他们点击一个图钉来选择它,然后点击用户界面中其他位置的删除按钮来删除该图钉?您可以使用类似这样的东西来跟踪最后选择的一个;

-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    // Do other stuff
    annotationToRemove = view.annotation;    
 }

您还可以实现 didDeselectAnnotationView 方法。

一如既往,Apple 提供了大量文档

Just remove the annotation using

[mapView removeAnnotation:annotationToRemove]

Presumably you have some form of UI to enable the user to choose which one they are dealing with? For example you could have a scenario where they tap a pin to select it, and then tap a delete button elsewhere in your UI to remove that pin? You could track which one was last selected using something a bit like this;

-(void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    // Do other stuff
    annotationToRemove = view.annotation;    
 }

You can also implement the didDeselectAnnotaionView method as well.

As always, there's copious documentation over at Apple

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文