I have been working on this problem for 6 hours and I am still struggling.
I have a mapview and I am adding MKPolygons like this:
for (MKPolygon *polygon in arrPolygon){
[mapView addOverlay:polygon];
[mapView addAnnotation:polygon];
}
I am finding which polygon overlay was tapped and select corresponding annotation programatically:
WildcardGestureRecognizer *tapges=[[WildcardGestureRecognizer alloc] init];
tapges.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [touches anyObject];
tappedOverlay = nil;
if([touch tapCount]==1){
for (id<MKOverlay> overlay in mapView.overlays)
{
MKOverlayView *view = [mapView viewForOverlay:overlay];
if ([overlay isKindOfClass:[MKPolygon class]] && view)
{
// Get view frame rect in the mapView's coordinate system
CGRect viewFrameInMapView = [view.superview convertRect:view.frame toView:mapView];
// Get touch point in the mapView's coordinate system
CGPoint point = [touch locationInView:mapView];
// Check if touch is within the view
if (CGRectContainsPoint(viewFrameInMapView, point))
{
tappedOverlay = overlay;
[mapView selectAnnotation:tappedOverlay animated:NO];
break;
}
}
}
}
};
When I do this, Both didSelectAnnotationView and didDeselectAnnotationView are called for the same MKAnnotationView object. My question is, why Deselect method is being called?
When I manually select Annotation, It does not call Deselect method, meaning it works fine.
Thank You !!!