我在地图视图中显示不同的注释点。我想为所有不同的注释显示不同的标题和副标题。我以以下方式实现了我的viewForAnnotation委托方法。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
{
NSLog(@"annotation Class %@", [annotation class]);
if ([annotation isKindOfClass:[HGMovingAnnotation class]]) {
static NSString *kMovingAnnotationViewId = @"HGMovingAnnotationView";
HGMovingAnnotationView *annotationView = (HGMovingAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:kMovingAnnotationViewId];
if (!annotationView) {
annotationView = [[HGMovingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kMovingAnnotationViewId];
}
//configure the annotation view
annotationView.image = [UIImage imageNamed:@"symbol-moving-annotation.png"];
annotationView.bounds = CGRectMake(0, 0, 20, 20); //initial bounds (default)
annotationView.mapView = mapView;
NSLog(@"Inside Moving Annotation");
return annotationView;
}
static NSString *kCustomAnnotationView = @"CustomAnnotationView";
MKPinAnnotationView* customPinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:kCustomAnnotationView];
if ([annotation isKindOfClass:[CLLocation class]]) {
MKAnnotationView *customAnnotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:kCustomAnnotationView];
customAnnotationView.image = [UIImage imageNamed:@"customAnnotation"];
customAnnotationView.canShowCallout = NO;
customAnnotationView.centerOffset = CGPointMake(2,-12);
NSLog(@"Inside Custom Annotation1");
return customAnnotationView;
} else {
customPinView.annotation = annotation;
customPinView.pinColor = MKPinAnnotationColorPurple;
NSLog(@"Inside Custom Annotation2");
return customPinView;
}
}
我想显示customPinView注释的标题和子标题。请帮我。