views:

708

answers:

1

I'm doing the following and always get green pins:

pin.pinColor = MKPinAnnotationColorRed;
        [self.mapView addAnnotation:pin];
        [pin release];

pin is of type "NSObject ". All pins come out as green. Should I be doing it differently?

+3  A: 

Make sure your pin class implements the MKAnnotation protocol and I believe to get a non-standard pin color, you'll have to implement the viewForAnnotation method.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"redpin"];
    newAnnotation.pinColor = MKPinAnnotationColorRed;
    newAnnotation.animatesDrop = YES;
    newAnnotation.canShowCallout = YES;
    return newAnnotation;
}
DyingCactus
Thanks. This looks similar to tableview dequeueing. Should I check for null on newAnnotion first and give back the instance if it already exist?
4thSpace
Yes, that's what the docs recommend though for my purposes I didn't bother. Check the link for viewForAnnotation. It mentions the dequeueReusableAnnotationViewWithIdentifier method.
DyingCactus