删除后选择Annotation然后重新添加Annotation

发布于 2024-09-16 10:27:01 字数 830 浏览 9 评论 0原文

大家好,我有一个关于 iPhone 的 mapKit 的棘手问题。

我正在使用 MapKit 框架,我想做的基本上就是单击一个图钉,重新加载它,然后在再次添加后显示它的 callOut。

这是我想要开始工作的代码。

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    NSLog(@"count of selected Annotations: %d",[mapView selectedAnnotations].count);
    MKAnnotation* pin = view.annotation;
    [mapView deselectAnnotation:pin animated:FALSE];
    [mapView removeAnnotation:pin];
    [mapView addAnnotation:pin];
    [self.mapView selectAnnotation:pin animated:TRUE];

一些观察:如果我注释掉removeAnnotations和addAnnotation行,我会进入无限循环,因为当我selectAnnotation:pin时,会调用回调(这是这个方法) ...否则,它不是,但那又是什么?为什么没有

[self.mapView selectAnnotation:pin animated:TRUE]; 

被调用?

我已经读了太多的书,花了太多的时间试图弄清楚对我的代码的解释和修复会比链接更有帮助。

提前致谢。 〜费多

Hey all, I got somewhat of a dense question about the mapKit for the iPhone.

I'm using the MapKit framework and what I'm trying to do is basically click a pin, reload it and then show it's callOut after it has been added again.

This is the code I'm trying to get to work..

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    NSLog(@"count of selected Annotations: %d",[mapView selectedAnnotations].count);
    MKAnnotation* pin = view.annotation;
    [mapView deselectAnnotation:pin animated:FALSE];
    [mapView removeAnnotation:pin];
    [mapView addAnnotation:pin];
    [self.mapView selectAnnotation:pin animated:TRUE];

A few observations: If I comment the removeAnnotations and addAnnotation lines out, I enter an infinite loop because when I selectAnnotation:pin, the callback (which is this method) is called... otherwise, it isn't, but then what is? why isn't

[self.mapView selectAnnotation:pin animated:TRUE]; 

being called?

I've already read far too much and broke my head for far too many hours trying to figure this out that an explanation and a fix to my code would be much more helpful than a link.

Thanks in advance.
~Fydo

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

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

发布评论

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

评论(1

七色彩虹 2024-09-23 10:27:01

所以我已经回答了我自己的问题...似乎单击注释后更改注释的最简单方法如下:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    MKAnnotation* pin = view.annotation;
    UIImageView * blackPin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PinUnchecked.png"]];
   [[mapView viewForAnnotation:pin] addSubview:blackPin];

将调用此委托方法,然后将显示一个annotationView气泡并且annotationView将更改其图像...这就是我需要做的一切...

So I've answered my Own Question... it seems that the easiest way to change the annotation upon clicking it, is as follows:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    MKAnnotation* pin = view.annotation;
    UIImageView * blackPin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PinUnchecked.png"]];
   [[mapView viewForAnnotation:pin] addSubview:blackPin];

This delegate method will be called, then an annotationView bubble will be displayed AND the annotationView will change it's image... which is all I needed done...

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