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]; 

被叫?

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

提前致谢。~飞度

4

1 回答 1

0

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

-(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 将更改其图像...这就是我需要做的...

于 2010-09-01T17:45:49.750 回答