我似乎无法在mapView:viewForAnnotation委托方法内部访问自定义MKAnnotation属性。据我了解,该方法将注释作为值。我正在尝试定位传入的每个注释的属性。
代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
//This actually returns a proper coordinate
NSLog(@"%f", annotation.coordinate.latitude);
//This gives me an error: Property 'annotationMarker' not found on object of type '__strong id<MKAnnotation>'
NSLog(@"%@", annotation.annotationMarker);
MKAnnotationView *testPin = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
testPin.image = [UIImage imageNamed:[[testArray objectAtIndex:1]annotationMarker]];
return testPin;
}
我认为自定义属性可能设置不正确,但是我可以在代码的其他部分记录这些批注的属性值。
我在犯某种语法错误吗?此委托方法是否以某种方式去除自定义属性?
最佳答案
您需要转换为自定义的MKAnnotation
-conformant类,例如
CustomAnnotation *customAnnotation = (CustomAnnotation *)annotation;
NSLog(@"%@", customAnnotation.annotationMarker);