Search code examples
iphone-sdk-3.0uibuttonmkmapviewmkannotation

How do I add a button to the subtitle of an MkMapView custom annotation?


Basically my program displays many annotations on a map. after the user clicks on one, It displays the title of the location. How can I add a button under the title that will display a new window with more information on the location? I would also be content with a button at the bottom of the screen that is greyed out until one location is selected.


Solution

  • In the viewForAnnotation method, set a button as the callout accessory view:

    annotationView.canShowCallout = YES;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annotationView.rightCalloutAccessoryView = button;
    

    You can use rightCalloutAccessoryView or leftCalloutAccessoryView but the documentation recommends putting a disclosure button on the right.

    Respond to the button press in the calloutAccessoryControlTapped method.