将可单击的注释添加到UIMapView

时间:2009-12-06 19:52:18

标签: 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];

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

戴夫

1 个答案:

答案 0 :(得分: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;
}