0

我正在使用以下代码创建我的 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;

}
4

1 回答 1

0

啊! 我发现了你的错误。

if(annotationView == nil)
    {
         MKPinAnnotationView *customPinView =  [[MKPinAnnotationView alloc]  initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"];
    }// YOU ARE MISSING THIS BRACKET 

如果它为零,它将像往常一样被分配和我们想要的其他东西。

于 2013-09-09T03:41:54.197 回答