You can achieve this through your viewForAnnotation
method in your MKMapViewDelegate
. If this method returns nil
then the map view will use the default annotation view. You can test the annotation to see if it is your subclass and then return a view or nil as appropriate. Something like -
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pin=nil;
if ([annotation isKindOfClass:[Annotation class]])
{
pin=(MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotation"];
if (pin == nil)
{
pin=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pin.image=[UIImage imageNamed:@"mappin.png"];
pin.centerOffset=CGPointMake(0.0, pin.image.size.height/-2);
pin.canShowCallout=YES;
}
}
return pin;
}