我使用以下代码创建我的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;
}
答案 0 :(得分:0)
啊!我抓住了你的错误。
if(annotationView == nil)
{
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"];
}// YOU ARE MISSING THIS BRACKET
如果它没有,它会像往常一样被分配和我们想要的其他东西。