iOS 无法访问 MKAnnotation 的属性

标签 ios objective-c mkmapview mkannotation mkannotationview

我似乎无法访问 mapView:viewForAnnotation 委托(delegate)方法中的自定义 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;
}

我想也许自定义属性设置不正确,但我可以在代码的其他部分记录这些注释的属性值。

我是否犯了某种语法错误?这个委托(delegate)方法是否以某种方式去除了自定义属性?

最佳答案

您需要转换为您的自定义 MKAnnotation -conformant 类,例如

CustomAnnotation *customAnnotation = (CustomAnnotation *)annotation;
NSLog(@"%@", customAnnotation.annotationMarker);

关于iOS 无法访问 MKAnnotation 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21321417/

相关文章:

iphone - 主线程在执行后台线程时正在等待[NSManagedObjectContext(_NSInternalAdditions)lockObjectStore]

ios - map 以北指向北极始终为 : programatically ios

ios - 为什么 UIView 旋转时不居中?

objective-c - 如何从 uitableview 单元格的不同部分中的数组生成行上的不同数据

iphone - 如何在 C++ 中获取 iPhone 上的语言环境?

ios - iphone 应用程序中的异步声音

ios - 在 map View 中放大当前位置

ios - 分享 MKMapView 截图

ios - 相互交换 Sprite 位置

iOS:通过电子邮件的 Firebase 邀请不起作用