2011-04-30 29 views
1

我有以下問題:iPad MapKit - 重新選擇一個引腳不起作用

我在地圖上有多個引腳。觸摸後,打開一個自定義彈出窗口並顯示信息。這工作完美。

我的問題是,如果您選擇同一個引腳兩次,彈出窗口不會打開,您必須觸摸另一個或單擊地圖中的某個位置。

我的代碼如下:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    MKAnnotationView* annotationView = nil; 
    CPPointOfInterest *myAnnotation = (CPPointOfInterest*) annotation; 

    if ([myAnnotation isKindOfClass:[MKUserLocation class]] || myAnnotation.poi_id <= 0) { 
     return nil; 

    } else { 
     NSString* identifier = @"Pin"; 
     MKPinAnnotationView* annView = (MKPinAnnotationView*)[mv_map dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if(nil == annView) { 
      annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease]; 
     } 

     [annView addObserver:self 
        forKeyPath:@"selected" 
        options:NSKeyValueObservingOptionNew 
       context:@"GMAP_ANNOTATION_SELECTED"]; 

     if(self.nearest_poi == myAnnotation) { 
      annView.pinColor = MKPinAnnotationColorGreen; 

     } else { 
      annView.pinColor = MKPinAnnotationColorRed; 

     } 

     annView.animatesDrop = YES; 

     annotationView = annView; 

     [annotationView setEnabled:YES]; 
     [annotationView setCanShowCallout:NO]; 

     return annotationView; 

    } 
} 

觀察報:

- (void)observeValueForKeyPath:(NSString *)keyPath 
         ofObject:(id)object 
         change:(NSDictionary *)change 
         context:(void *)context{ 

    NSString *action = (NSString*)context; 
    if([action isEqualToString:@"GMAP_ANNOTATION_SELECTED"]){ 
     BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue]; 
     if (annotationAppeared) { 
      // show popup 
      } 
    } 
} 

我也曾嘗試didSelectAnnotationView梅索德,這也只是適用於第一次點擊的事件。

我已經搜索了幾個小時,但沒有找到...:/

有誰知道我的問題的解決方案,請給我一個提示...

感謝和問候, 馬修

回答

1

我使用的是酥料餅來顯示信息:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController 
{ 
    if (popover) 
    { 
     [popover release]; 
     popover = nil; 
    } 

    LocatorSearchDealer *dealer = [[mapView selectedAnnotations] objectAtIndex:0]; 

    //without this line I cannot immediately reselect the same annotation. 
    [mapView deselectAnnotation:dealer animated:NO]; 
} 
3

你面前你可以通過取消的MapView註釋再次選擇它。試試看:

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

[mapView deselectAnnotation:view.annotation animated:NO]; 

} 
+0

+1這對我有用。乾杯!! – Tariq 2013-05-09 11:30:57