Dragging and dropping annotations triggers multiple delegation of the drag and drop state method

This is a bit unclear.

There is a method in this MKMapViewDelegate that should tell you when you start and finish dragging and dropping the annotation view. I did this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (oldState == MKAnnotationViewDragStateStarting && newState == MKAnnotationViewDragStateEnding) { NSLog(@"Ending drag"); } if (newState == MKAnnotationViewDragStateStarting) { NSLog(@"Beginning drag"); } } 

This type of work. However, when I stop dragging and dropping the annotation again, this method runs twice, then 3 times, etc. So, the console displays:

 Beginning drag Ending drag Beginning drag Beginning drag Ending drag Ending drag Beginning drag Beginning drag Beginning drag Ending drag Ending drag Ending drag Beginning drag Beginning drag Beginning drag Beginning drag Ending drag Ending drag Ending drag Ending drag 

Any ideas on what causes this?

+4
source share
1 answer

I seemed to solve this by adding:

 [annotationView setDragState:MKAnnotationViewDragStateNone]; 

in the "end drag" section of the if statement.

+10
source

All Articles