删除后选择Annotation然后重新添加Annotation
大家好,我有一个关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我已经回答了我自己的问题...似乎单击注释后更改注释的最简单方法如下:
将调用此委托方法,然后将显示一个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:
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...