Can anyone help me on how to use the
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
method.
I am trying to tell the annotation pins on my project appart and I can't figure out h开发者_如何学JAVAow. Every pin has a disclosure button but I can't figure out how the program will know which pin-button is being pushed.
You can use a bunch of different techniques here.
For example, you could keep an ivar for each annotationView and do this:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
if (view == myFirstAnnotationView) {
//do something
}
if (view == mySecondAnnotationView) {
//do something
}
if (view == myThirdAnnotationView) {
//do something
}
}
Or, you could use the tag value of the annotation view.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
if ([view.tag isEqualToString@"one"]) {
}
if ([view.tag isEqualToString@"two"]) {
}
}
Or, you could subclass MKAnnotationView to add some behavior to it.
- (void)mapView:(MKMapView *)mapView annotationView:(MyMKAnnotationViewSubclass *)view calloutAccessoryControlTapped:(UIControl *)control {
[view doAMethodIMadeWhenISubclassed];
}
None, of these is a complete solution, and it would be hard to provide one without beter understanding your application and design, but what they all have in common is changing the annotationView before you add it to the map in order to decide what to do after the delegate callback happens. I hope this leads you down the right path.
精彩评论