The leftCalloutAccessoryView property is a property of the MKAnnotationView class (not in the MKAnnotation protocol).
In the viewForAnnotation delegate method of MKMapView, you provide an MKAnnotationView for your annotations. In that method, check if the annotation type is your custom annotation type using isKindOfClass and set the view's properties as needed.
In your NeighborMapAnnotation class, you could store the imageView as a UIImageView property and set that when creating the annotation.
In viewForAnnotation, you would set the view's leftCalloutAccessoryView to the annotation's imageView.
Edit:
Here's one way to implement it...
Add an image property to your custom annotation class:
@interface NeighborMapAnnotation : NSObject <MKAnnotation> {
...
UIImage *image;
}
...
@property (nonatomic, retain) UIImage *image;
@end
At the place where you create your annotations, set the image property:
NeighborMapAnnotation *neighbor = [[NeighborMapAnnotation alloc] initWithCoordinate:aCoordinate];
neighbor.image = [UIImage imageNamed:@"someimage.png"];
//the image could be different for each annotation
...
In the viewForAnnotation delegate method (make sure map view's delegate is set):
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[NeighborMapAnnotation class]])
{
static NSString *AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView)
{
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else
{
pinView.annotation = annotation;
}
UIImageView *leftCalloutView = [[UIImageView alloc]
initWithImage:((NeighborMapAnnotation *)annotation).image];
pinView.leftCalloutAccessoryView = leftCalloutView;
[leftCalloutView release];
return pinView;
}
return nil;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…