質問

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

役に立ちましたか?

解決

MKAnnotationView * view = ...

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top