注释标注上的附件按钮

Accessory button on annotation callout

我正在尝试向我的地图注释添加一个附件按钮,但我无法使用它。我已经搜索了很多,但似乎没有任何效果。请帮助我!

这是我的代码:

//Annotations

//Pildammsparken
CLLocationCoordinate2D pildLocation;
pildLocation.latitude = PILD_LATITUDE;
pildLocation.longitude = PILD_LONGITUDE;
//Malmöhus Slott
CLLocationCoordinate2D malmohusLocation;
malmohusLocation.latitude = MALMOHUS_LATITUDE;
malmohusLocation.longitude = MALMOHUS_LONGITUDE;

//Pildammsparken - Annotation
MapPin *annPild = [[MapPin alloc] init];
annPild.title = @"Title";
annPild.subtitle = @"Subtitle";
annPild.coordinate = pildLocation;
[mapview addAnnotation:annPild];
//Malmöhus slott - Annotation
MapPin *annMalmohus = [[MapPin alloc] init];
annMalmohus.title = @"Title";
annMalmohus.subtitle = @"Subtitle";
annMalmohus.coordinate = malmohusLocation;
[mapview addAnnotation:annMalmohus];

[mapview setShowsPointsOfInterest:NO];

我想要在小注释末尾有一个按钮,可以将您带到可以阅读更多内容的页面。

将您的 viewcontroller 设置为地图视图的委托并实现以下方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return nil;
    }

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"PinAnnotationView"];
    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinAnnotationView"];
        annotationView.canShowCallout = YES;
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    } else {
        annotationView.annotation = annotation;
    }

    return annotationView;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    MKPointAnnotation *annotation = view.annotation;
    NSLog(@"user tapped annotation with title: %@", annotation.title);
}