문제

나는 최근에 만났다 이 웹 사이트 그리고 나는 내 콜 아웃 뷰 버튼 (이미지에서)에 추가하려고 노력했습니다.

웹 사이트 예제의 코드는 잘 작동하지만 프로젝트에 동일한 코드를 추가하려고 할 때 동일한 결과를 얻지 못합니다.

분명히 내가 놓친 것이 있지만 나는 이것을 해결할 수없는 것 같습니다!

주석을위한 내 코드는 다음과 같습니다.

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

모든 도움이 감사하겠습니다! :)

도움이 되었습니까?

해결책 3

내 자신의 질문에 대답해서 죄송하지만 이것은 mkmapview의 대의원을 ViewController로 설정하여 해결되었습니다. PHEW, 그것을 알아내는 데 시간이 걸렸고 너무 간단합니다 !!

다른 팁

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

[UIButton buttonWithType:UIButtonTypeDetailDisclosure];

여기에서했던 것처럼 대상을 설정하는 대신 :

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

기본 대의원을 사용할 수 있습니다.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top