views:

643

answers:

1

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

+4  A: 

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;
}
Magic Bullet Dave
This works but instead of [disclosureButotn addTarget] you should probably be using the predefined delegate method - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
Jasconius
Thanks Jasconius... will give it a whirl...
Magic Bullet Dave