Domanda

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

È stato utile?

Soluzione

MKAnnotationView * view = ...

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top