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.
A:
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.
DyingCactus
2010-05-19 00:58:49
I am new at this, so please forgive me when I ask where this viewForAnnotation method is exactly. I have three .h/.m files for the main view:AnnotationView, Annotation, and MainViewController. which file should I place this under?
kevin Mendoza
2010-05-19 02:03:27
viewForAnnotation is a method you implement in the class that implements the MKMapViewDelegate protocol. I assume for you this would be MainViewController. I suggest looking at the Apple sample app MapCallouts. In there, viewForAnnotation is implemented similarly to the example I gave (see MapViewController.m). The documentation link in my answer has a link to MapCallouts or you can search apple.com for it.
DyingCactus
2010-05-19 02:39:19