简体   繁体   中英

When a annotation is clicked how can I pass data to its view controller?

When an MKAnnotation is clicked I need to call a function in its view controller, and pass it two NSStrings contained in the annotation. How can I achieve this?

Just assign your view controller as the map view's delegate and implement

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

MKAnnotationView has an annotation property that you can use to get your strings.

Probably the annotations are some kind of buttons? In this case, they are the sender of the action -> A reference to the clicked annotation is passed as argument to the called function!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM