2009-09-16 2 views
10

나는 최근에 this website을 보았습니다. 이미지에서 버튼을 보도록 전화를 걸었습니다.MKMapView에 액세서리보기 버튼을 추가하면 주석을 불러 낼 수 있습니까?

웹 사이트 예제의 코드는 정상적으로 작동하지만 동일한 코드를 프로젝트에 추가하려고하면 동일한 결과가 나타나지 않습니다.

내가 놓친 부분이 분명 있지만이 부분을 해결할 수는 없습니다.

여기에 주석 내 코드입니다 :

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
    annView.pinColor = MKPinAnnotationColorGreen; 

    UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    advertButton.frame = CGRectMake(0, 0, 23, 23); 
    advertButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    advertButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 

    [advertButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal]; 
    [advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

    annView.rightCalloutAccessoryView = advertButton; 

    annView.animatesDrop=TRUE; 
    annView.canShowCallout = YES; 
    annView.calloutOffset = CGPointMake(-5, 5); 
    return annView; 
} 

어떤 도움을 주시면 감사하겠습니다! :)

+0

을, 당신이 제공 한 링크가 죽었습니까 –

답변

4

내 자신의 질문에 대한 답변을 드려 죄송하지만이 문제는 MKMapView의 대리인을 ViewController로 설정하여 해결되었습니다. 휴, 그걸 알아내는 데 시간이 좀 걸렸어. 그렇게 간단 해 !!

15

그 사람은 세부 정보 공개를 모방하기 위해 사용자 지정 이미지를 사용하고 있습니다. 당신은 실제로 아주 쉽게 표준 상세 공개를 얻을 수 있습니다 :

[UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
+0

아, 덕분에, 그들이 할 수있는 방법을 항상 유용합니다 :) –

11

을 대신 당신이 여기처럼 목표를 설정하는 :

[advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

당신은 기본 위임 사용할 수 있습니다 : 불행하게도

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
관련 문제