我正在使用以下代码创建我的 pin 注释标注,但我的详细信息披露按钮和我的自定义图像没有显示。肯定有关系,if([annotation isKindOfClass:[CustomAnnotation class]])
但不知道是什么。我在这里做错了什么?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isKindOfClass:[CustomAnnotation class]])
{
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomAnnotation"];
if(annotationView == nil)
{
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"];
if([[customPinView.annotation title] isEqualToString:@"HQ"])
{
customPinView.pinColor = MKPinAnnotationColorPurple;
}
else
{
customPinView.pinColor = MKPinAnnotationColorRed;
}
customPinView.canShowCallout = YES;
customPinView.animatesDrop = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}