2011-04-30 2 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 메도을 시도,이 또한 바로 첫 번째 클릭 이벤트에 대한 작동합니다.

나는 몇 시간 동안 검색 한

,하지만 아무것도 ... 찾을 수 있습니다 :/

사람이 내 문제에 대한 해결책을 알고 있습니까, 나에게 힌트를주세요 ...

감사 인사를, 당신은 당신이 할 수있는 전에지도보기를 통해 주석을 해제해야

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

답변

1

은 내가 정보를 표시하는 팝 오버를 사용하고 있습니다 다시 선택하십시오. 다음을 시도하십시오 :

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

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

} 
3

: 매튜

+0

+1이 작품은 나를 위해 작동합니다. 건배!! – Tariq

관련 문제