I got an app with MKMapView and large number of pins on this map.
Every pin got rightCalloutAccessoryView. I create it in this way:
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
How should i know, which pin was tapped? Thnx
In the
showDetails:method, you can get the pin tapped from the map view’sselectedAnnotationsarray. Even though the property is anNSArray, just get the first item in the array since the map view only allows one pin to be selected at a time:By the way, instead of doing
addTargetand implementing a custom method, you can use the map view’scalloutAccessoryControlTappeddelegate method. The annotation tapped is available in theviewparameter:Make sure you remove the
addTargetfromviewForAnnotationif you usecalloutAccessoryControlTapped.