根据位置特定值分配pinColor?

时间:2014-08-26 19:29:39

标签: ios colors mkmapview mapkit mkannotation

我正在从数据库中检索一些位置,并希望根据位置的类别自定义引脚的颜色。例如,所有“收藏”位置可能都是紫色(甚至使用自定义图像)。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    if([annotation isKindOfClass:[MKUserLocation class]]) { // This is the current location
        return nil;     // Don't change anything... return
    }

    static NSString *identifier = @"myAnnotation";         // Create a reusable class
    MKPinAnnotationView * annotationView = (MKPinAnnotationView*) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];

        // .. some kind of test goes in here...

        // If this is a favourite annotation, then show it in Purple
        annotationView.pinColor = MKPinAnnotationColorPurple;

        // Without a proper test, the current code has all pins go Red

        // If it's a normal Annotation, then show it in Red
        annotationView.pinColor = MKPinAnnotationColorRed;
    } else {
        annotationView.annotation = annotation;
    }
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    return annotationView;
}

我想要的是能够查询正在显示的特定注释。我假设这个方法是根据当时显示的点调用的,所以设置pinColor的顺序不是那么可预测的。

我想引用NSManagedObject的特定属性来确定设置引脚的颜色。我知道我只有3针颜色。那不是问题。我只想了解它是如何工作的,然后我可以使它更复杂。

我不想对描述进行测试,因为多个描述可能相同但位置不同且类别也不同。例如,是否可以在Annotation创建中使用指针指向可在viewForAnnotation中引用的另一个类?

有什么想法吗?

0 个答案:

没有答案
相关问题