Question

When an annotation on the map is selected and the callout accessory control button is tapped I need to be able to find the index of that annotation. The index is going to be used to look at information in an array to prepare for the next view controller (detailed).

How do I find the index of an annotation?

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"Button clicked");
[self performSegueWithIdentifier:@"showDetail" sender:self];
}

Thanks

Was it helpful?

Solution

MKAnnotationView * view = ...

NSUInteger index = [mapView.annotations indexOfObject:view.annotation];

OTHER TIPS

It has no index path like there is in a table view. Use your own model class as an annotation by making it conform to MKAnnotation, then use whatever logic you have for tracking individual model items. Or just pass the model item as-is to the next view controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top