It sounds like the pin views are being re-used from previous annotations and their pinColor
is not being updated when they are re-used.
In the answer that you linked to, there is this statement:
Finally, in viewForAnnotation, right before returning the view, set the pinColor based on grupo:
The pinColor
needs to be set whether you are creating a new view or if you are re-using a dequeued view. A dequeued view may have had its pinColor
set for an annotation in a different group.
The code shown in the question is only setting pinColor
when creating a new view.
That code needs to be moved out of that block and put right before the return annotationView;
line:
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//the code to set the pinColor goes HERE...
myAnnotation *myAnn = (myAnnotation *)annotation;
NSLog(@"ANNOTATION GRUPO = %d",myAnn.grupo);
switch (myAnn.grupo)
{
case 1:
annotationView.pinColor = MKPinAnnotationColorRed;
break;
case 2:
annotationView.pinColor = MKPinAnnotationColorGreen;
break;
case 3:
annotationView.pinColor = MKPinAnnotationColorPurple;
break;
default:
annotationView.pinColor = MKPinAnnotationColorPurple;
break;
}
return annotationView;