MKAnnotation Custom Callout button general action — how to know which Annotation it's coming from? (iPhone)

StackOverflow https://stackoverflow.com/questions/9046337

문제

I'm developing a MapKit app which uses a whole bunch of MKAnnotations to mark locations. What I want is to put buttons into the callouts which the user can press to perform an action on the selected location. So far I have seen examples where you can put a specific handler onto each callout, like the apple sample code "MapCallouts".

I want to use one handler for all of the annotation callouts which is general purpose, where I would ideally pass in the MKAnnotation for the active callout.

I've searched and searched in Google to no avail, can anybody give me a pointer or a link?

Thanks!

도움이 되었습니까?

해결책

Instead of adding your own handler method using addTarget and then using the selectedAnnotations property to figure out which annotation was tapped, I prefer using the calloutAccessoryControlTapped delegate method.

In that delegate method, the annotation tapped is accessed using view.annotation and if you've defined a custom annotation class with additional properties, you can do a cast to access them using (MyAnnotationClass *)view.annotation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top