2011-10-28 3 views
12

지도 주석에 올바른 설명 선 액세서리를 추가하는 방법을 알고 싶습니다. 내가 시도하는 모든 것이 어디에도없는 것처럼 보이므로 어떤 도움을 주시면 감사하겠습니다.오른쪽 설명 선 액세서리 방법 및 구현

편집

나는 코드 줄을 시도했지만 다른 아무것도 주석에 발생하지 않습니다.

- (MKAnnotationView *)mapview:(MKMapView *)sender viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
MKAnnotationView *aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""]; 
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
aView.canShowCallout = YES; 
aView.annotation = annotation; 
return aView; 
} 
+0

당신이 시도 무엇을 당신이 얻을 정확히 어떤 오류 또는 문제 보여줄 수 있습니까? – Anna

답변

34

메서드 이름이 잘못되었습니다. 그것은 자본 VmapView해야한다 :

- (MKAnnotationView *)mapView:(MKMapView *)sender 
      viewForAnnotation:(id <MKAnnotation>)annotation 

오브젝티브 C는 대소 문자를 구분합니다.

여전히 메서드가 호출되지 않으면지도 뷰의 delegate이 설정되지 않은 것입니다. 코드에서 self으로 설정하거나 인터페이스 작성기에서 파일 소유자에게 대리인을 첨부하십시오.

주석을 추가하기 전에 title을 설정해야합니다. 그렇지 않으면 설명 선이 계속 표시되지 않습니다.

위의 변경 사항은 액세서리 버튼이 나타나지 않도록 수정해야합니다.


다른 어떤 관련이없는 제안 ... viewForAnnotation에서

, 당신은 dequeueReusableAnnotationViewWithIdentifier를 호출하여 주석보기 재사용을 지원해야한다 : 프로젝트 ARC를 사용하는 경우

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

    MKPinAnnotationView *aView = (MKPinAnnotationView *)[sender 
       dequeueReusableAnnotationViewWithIdentifier:reuseId]; 
    if (aView == nil) 
    { 
     aView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation 
        reuseIdentifier:reuseId] autorelease]; 
     aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     aView.canShowCallout = YES; 
    } 

    aView.annotation = annotation; 

    return aView; 
} 

autorelease를 제거합니다. 그런데


는, 구현, 액세서리 버튼을 눌러 calloutAccessoryControlTapped 대리자 메서드를 응답하기 :

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
     calloutAccessoryControlTapped:(UIControl *)control 
{ 
    NSLog(@"accessory button tapped for annotation %@", view.annotation); 
} 
관련 문제