简体   繁体   中英

MKMapView annotation click event

When I click on the pin, annotation view is opened with detailed disclosure button.
When I touch detailed disclosure button next view is called,I need same functionality when I touch on annotation.

There is one delegate method in MKMapViewDelegate, When you select an annotation this method will help you to track which annotation got selected and than you may message to any selector you want ;).

mapView:didSelectAnnotationView:

Tells the delegate that one of its annotation views was selected.

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
Parameters
mapView

The map view containing the annotation view. view The annotation view that was selected. Discussion

You can use this method to track changes in the selection state of annotation views.

Availability Available in iOS 4.0 and later. Declared In MKMapView.h

You can use this code -

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

rightButton.tag = annotationIndex;

[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];

pinView.rightCalloutAccessoryView = rightButton;

In this "showDetails" should be your custom IBAction in which you code your functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM