【问题标题】:Pin Color not Changing引脚颜色不变
【发布时间】:2013-09-13 07:33:56
【问题描述】:

如果图钉的标题是“HQ”,我创建了一个 if-then 语句来显示一个紫色图钉。绿色引脚正确显示。有谁知道为什么我的紫色针脚颜色还是红色?

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if([annotation isKindOfClass:[MyAnnotation class]])

    {
        static NSString *annotationIdentifier=@"annotationIdentifier";

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];

        if(annotationView)
        {
            annotationView.annotation = annotation;
        }
        else
        {
            annotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
            if([[annotationView.annotation title] isEqualToString:@"HQ"])
            {

                //The pin for the HQ should be purple
                annotationView.pinColor = MKPinAnnotationColorPurple;
                [annotationView setAnimatesDrop:YES];

            }
            else
            {
                //All other new pins should be "green" by default
                annotationView.pinColor = MKPinAnnotationColorGreen;
                annotationView.canShowCallout = YES;
                annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                [annotationView setAnimatesDrop:YES];

            }
        }


        return annotationView;

    }

    return nil;

}

【问题讨论】:

    标签: ios mapkit


    【解决方案1】:

    地图重用注释视图(或提供这样做)

    与 tableView 的单元重用相同。


    现在在初始化时设置引脚颜色,但在重复使用时不设置。所以一个大头针总是相同的颜色。

    针对不同的情况使用不同的重用标识符!

     static NSString *annotationIdentifier= ([annotation.title isEqualToString:@"HQ"]) ? @"HQ" : "OTHER";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-19
      相关资源
      最近更新 更多