Iphone annotations pins and buttons

Can anyone help me use

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

method.

I am trying to tell annotations in my project and I cannot figure out how to do this. Each pin has a disclosure button, but I can't figure out how the program finds out which button is pressed.

+4
source share
1 answer

Here you can use a bunch of different methods.

For example, you can save 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 can use the tag value in 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 can subclass MKAnnotationView to add some kind of behavior to it.

 - (void)mapView:(MKMapView *)mapView annotationView:(MyMKAnnotationViewSubclass *)view calloutAccessoryControlTapped:(UIControl *)control { [view doAMethodIMadeWhenISubclassed]; } 

No, this is a complete solution, and it would be difficult to provide one without understanding your application and design, but all they have in common is changing the View annotation before adding it to the map to decide what to do after the delegate callback. Hope this leads you to the right path.

+2
source

Source: https://habr.com/ru/post/1311562/


All Articles