Rich
Rich

Reputation: 81

mapView:annotationView:calloutAccessoryControlTapped: is giving me a UITouchesEvent instead of a MKAnnotationView?

I'm trying to implement the mapView:annotationView:calloutAccessoryControlTapped: method in my iPhone app. The method is getting called, but when I try to use the view passed to it

Annotation* temp = (Annotation *)view.annotation;

the app crashes with the error.

2011-03-29 12:51:54.453 Flora[3316:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent annotation]: unrecognized selector sent to instance 0x6d13410'

In the debugger, it seems as if the view is a UITouchesEvent, not a MKAnnotationView.

I've read the other questions that people have had with this method, but they all get it to work after they use the annotation propery of the view passed in. This is not working for me.

Upvotes: 0

Views: 2065

Answers (1)

user467105
user467105

Reputation:

In the viewForAnnotation method, when setting the callout accessory view, are you doing an addTarget on the button? (If you are, don't.)

[rightButton addTarget:self 
    action:@selector(mapView:annotationView:calloutAccessoryControlTapped:) 
    forControlEvents:UIControlEventTouchUpInside];

Do not add the delegate method as a target for the button. The delegate method will be called automatically with the right parameter values when the callout accessory is pressed (if the map view's delegate has been set). If you have a line like the above in viewForAnnotation, remove it.

Upvotes: 2

Related Questions