2010-12-07 2 views

답변

-2

우리는 클릭하여 주석을 표시 할 수 있습니다.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{ 
    static NSString *identifier = @"Pin"; 

    MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
    pin.canShowCallout = YES; 
    [pin setSelected:YES animated:NO]; 

    return [pin autorelease]; 
} 
+0

코드에 메모리 누수가 있으며 위임 메서드를 구현하는 데 권장되는 방법이 아닙니다. 성능상의 이유로 기존 annotationView를 재사용하고 싶을 것이다. –

2

당신은 당신이 선택하고 -setSelected:animated:를 호출하려는 MKAnnotationView 인스턴스를 찾을 필요가 : 다음 코드를 사용합니다. 예를 들어

, 당신 루프 할 수있는이 같은 MKMapView의 주석 :

for (YOURCLASSHERE *a in mapView.annotations) { 
    // Your current position (if shown) is an annotation as well. Thus check for the right class! 
    if ([a isKindOfClass:[YOURCLASSHERE class]]) { 
     // insert some smart if statement here, if you have multiple annotations! 
     [[mapView viewForAnnotation:a] setSelected:YES animated:YES]; 
    } 
} 

YOURCLASSHERE가 MKAnnotation 프로토콜을 구현하는 클래스입니다.

물론 annotationView를 알고 있다면 루프가 불필요합니다.

+0

고마워요. – JohnWhite

+0

다음 질문으로 해결해주세요. –

4

사용 해보세요 :

[mapView selectAnnotation:annotation animated:YES]도 작동 것으로 보인다.

희망이 도움이됩니다.

관련 문제