2010-02-26 5 views
20

위치 제목, 설명, 날짜, 위치 이름과 같은 자세한 정보를 MKAnnotation에 추가하고 싶습니다. 따라서 필요한 네 줄이 될 것입니다. 그러나 제목과 부제 인 MKAnnotation에 전달할 수있는 매개 변수는 2 개뿐입니다. 지도에 세부 정보를 추가하려면 어떻게해야합니까? Plz 도와주세요 .. 미리 감사드립니다.iOS의 MKAnnotation에 세부 정보를 추가하는 방법

+3

라고 부름을 사용하고 있습니다. 자막에 추가되는 세부 사항을 추가하여 시도했습니다 ..하지만 한 줄로 나타났습니다. 어떻게 여러 줄을 자세히 표시 할 수 있습니까? –

답변

15

맞춤형 MKAnnotationView 개체를 만드는 방법을 살펴 보겠습니다. 기본적으로지도 주석에 맞게 조정 된 UIView입니다. 그 객체에는 4 개의 사용자 정의 레이블이있을 수 있습니다. 당신의 MKMapViewDelegate 클래스에서

, 당신은 viewForAnnotation 방법 구현 :

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

    // determine the type of annotation, and produce the correct type of annotation view for it. 
    CustomMapAnnotation* myAnnotation = (CustomMapAnnotation *)annotation; 

    NSString* identifier = @"CustomMapAnnotation"; 
    CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

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

    annotationView = newAnnotationView; 
    [annotationView setEnabled:YES]; 
    [annotationView setCanShowCallout:YES]; 

    return annotationView; 
} 

을 그리고 그 단계 튜토리얼, check out this video에 의해 단계를 원하는 경우에 당신이 ... 주석이 이제까지 당신의 사용자 정의보기를 표시합니다.

희망이 ...

편집

내가 실제로 단지 사과 dev에 사이트에 새로운 Maps example을 발견하는 데 도움이 당신이 통과하는 데 필요한 모든 소스 코드가 있습니다. 그들은 또한 사용자 정의

+0

UR 응답에 대해 감사드립니다. 기본 풍선에 세부 사항을 원하는 형식으로 추가 할 수 있습니까 (예 : 개행)? UILabel을 MKPinAnnotationView의 rightCalloutAccessoryView에 추가하여 시도했습니다. 하지만 그 좋은 lloking nice.thanks 사전에 –

+0

나는 그것을하려고하는 방식으로하려고하지 않을거야 ... 애플은 MKAnnotationView 클래스로 확장 할 수 있도록 주석을 설정했습니다. 당신이 그것을하고있는 방식으로 rightCalloutAccessoryView를 오버라이드하려고 시도하는 것은 좋은 방법이 아닙니다 ... 당신은 프레임 워크와 싸우고 있으며 이상한 결과를줍니다. 커스텀 어노테이션을 원한다면, 내가하는 가장 좋은 방법은 내가 설명한 방식이다. –

+0

자세한 내용을 보려면 새 편집을 참조하십시오. –

관련 문제