문제

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