将可单击的注释添加到UIMapView

Mag*_*ave 5 iphone mkmapview

我想在MapView上添加一个注释,上面有透露按钮,我无法弄明白.

我创建了一个符合MKAnnotation协议的PlaceMark类,然后创建MapView并添加PlaceMark:

// Add annotation information
PlaceMark *venuePlacemark = [[PlaceMark alloc] initWithCoordinate:location];
venuePlacemark.locationTitle = [locationDictionary valueForKey:VENUE_NAME_KEY];
venuePlacemark.locationSubtitle = @"Touch to show in Google Maps";

// Create the accessory button on the placemark
[venueMap addAnnotation:venuePlacemark];
[venueMap setRegion:region animated:TRUE];
[venueMap regionThatFits:region];
Run Code Online (Sandbox Code Playgroud)

这一切都有效,并显示一个引脚,触摸时显示正确的呼出文本.我无法弄清楚如何在呼叫中添加公开按钮.对不起,如果这是基本的,任何帮助将不胜感激.

戴夫

Mag*_*ave 9

想想我已经弄明白了...实现了以下委托方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *dropPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"venues"];

    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [disclosureButton addTarget:self action:@selector(mapCallOutPressed:) forControlEvents:UIControlEventTouchUpInside];

    dropPin.rightCalloutAccessoryView = disclosureButton;
    dropPin.animatesDrop = YES;
    dropPin.canShowCallout = YES;

    return dropPin;
}
Run Code Online (Sandbox Code Playgroud)

  • 这可行但不是[disclosureButotn addTarget]你应该使用预定义的委托方法 - (void)mapView:(MKMapView*)mapView annotationView:(MKAnnotationView*)view calloutAccessoryControlTapped:(UIControl*)control (2认同)