如何在“viewForAnnotation”中访问当前注释的类?

时间:2014-08-22 21:46:35

标签: ios objective-c annotations callout

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"User"];
    UIImageView *myCustomImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    MyPin.leftCalloutAccessoryView = myCustomImage;
}

我想将注释的leftCalloutAccessoryView设置为我在运行时才知道的特定图像。我在创建的每个单独的注释中定义了所需的特定图像,但是如何在此函数中访问特定注释的类,以便我可以相应地设置myCustomImage?

2 个答案:

答案 0 :(得分:0)

这应该是您正在寻找的:

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

    }
}

答案 1 :(得分:0)

使用此功能,然后您可以使用temp访问您班级的某些成员。

Pin *temp = (Pin *)annotation;