1

I have three pins on a mapview. I'd like to give each one a different color. In the delegate method viewForAnnotation, I'm doing this:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"anAddress"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}

I was thinking to create an array of MKPinAnnotationViews but how can I get the correct one since the delegate method isn't indexed to anything?

4thSpace
  • 43,672
  • 97
  • 296
  • 475

1 Answers1

3

To distinguish between UIView, you can use the tag property and its corresponding viewWithTag: method.

However, in your context, I would recommend adding the color to your annotation class. Then you can ensure that you don't reuse the same caller for multiple pins.

notnoop
  • 58,763
  • 21
  • 123
  • 144
  • You mean by making a custom MKPinAnnotationView? But still, how do I call the correct one when the delegate fires? Or does it matter? If not, I can just keep a class level counter to pull them out of an array upon each firing of the delegate. – 4thSpace Jul 15 '09 at 18:08
  • I mean that your id class contains a field for the color indicator, or a counter you use to determine the color. – notnoop Jul 15 '09 at 18:21