Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a clickable annotation to a UIMapView

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 Google 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

like image 865
Magic Bullet Dave Avatar asked Dec 06 '09 19:12

Magic Bullet Dave


Video Answer


1 Answers

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;
}
like image 156
Magic Bullet Dave Avatar answered Oct 01 '22 02:10

Magic Bullet Dave