开发者

Adding a clickable annotation to a UIMapView

开发者 https://www.devze.com 2022-12-13 13:50 出处:网络
I want to add an annotation to a MapView with disclosure button on it and I can\'t figure it out. I have created a PlaceMark class that conforms to the MKAnnotation protocol and then create the MapVi

I want to add an annotation to a MapView with disclosure button on it and I can't figure it out.

I have created a PlaceMark class that conforms to the MKAnnotation protocol and then create the MapView and add the PlaceMark:

// Add annotation information
PlaceMark *venuePlacemark = [[PlaceMark alloc] initWithCoordinate:location];
venuePlacemark.locationTitle = [locationDictionary valueForKey:VENUE_NAME_KEY];
venuePlacemark.locationSubtitle = @"Touch to show in Go开发者_高级运维ogle Maps";

// Create the accessory button on the placemark
[venueMap addAnnotation:venuePlacemark];
[venueMap setRegion:region animated:TRUE];
[venueMap regionThatFits:region];

This all works and a pin is displayed that when touched displays the correct call out text. I cannot figure out how to add a disclosure button to the call out. Sorry if this is elementary and any help would be appreciated.

Dave


Think I've figured it out... Implemented the following delegate method:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号