Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclass MKAnnotationView

Did somebody ever override successfully the method setDragState in MKAnnotationView? If I try to google for it with "mkannotationview setDragState" I only get three hits! One of them is my other post on stackoverflow ;)

The reference says that when subclassing MKAnnotationView the subclass has to care about the dragstate. But it does not say how to exactly. Only setting the dragstate to MKAnnotationViewDragStateDragging or rather MKAnnotationViewDragStateCanceling seems not to be enough. Because if I just do that, one of the issues for example is that the mapview does not receive the mapView:annotationView:didChangeDragState:fromOldState: delegate function.

I tried to override it by setting the dragState also in the super class. But at this point other errors occur: For example if I drag the annotationView and my finger runs off the screen, the app crashes with something like "can not remove observer for keypath dragstate" (but my subclass does not any observers I know about). So it seems to that there are other things to care of.

In this post on apple developer forum https://devforums.apple.com/message/203107#203107 aroonicus, a guy from apple, mentions that you have to override [MKAnnotationView setDragState:] but sadly he does not tell how to.

Can anybody help? Does anybody know howto override setDragState? Did anybody created a working subclass of MKAnnotationView overriding setDragState?

Bye,

Ben

like image 411
Ben Zwak Avatar asked Oct 26 '22 06:10

Ben Zwak


1 Answers

Refer this thread refer to the second answer where a custom annotation view class is used to override the existing one. It works

Subclassing MKAnnotationView and overriding setDragState

like image 72
Uttam Ukkoji Avatar answered Nov 15 '22 09:11

Uttam Ukkoji