2010-08-31 82 views
0

嘿所有,我有一個關於iPhone的mapKit密集的問題。selectAnnotation刪除後,然後重新添加註解

我正在使用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:針,回調(這是這種方法)被稱爲...否則,它不是,但那麼是什麼?爲什麼不是

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

被調用?

我已經讀得太多了,並且打破了我的頭太多的時間試圖弄清楚,解釋和修復我的代碼會比鏈接更有幫助。

在此先感謝。 〜Fydo

回答

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

此委託方法將被調用,那麼註釋視圖氣泡將被顯示,並且註解視圖將改變它的圖像......這就是我所需要做的......