当我添加注释时,我会为其添加一个“.tag”。但是我永远无法用以下方法读取标签。
`- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation`
MKAnnotationView *annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
annView.canShowCallout = YES;
NSLog(@"annView.tag = %d", annView.tag);
return annView;
}
NSLog 始终为 0。有人能解释一下吗?
值得一提的是,如果我使用 NSLog 注释,我确实会看到该标签。
2010-09-10 10:21:27.612 [1328:207] annotation = <BarPin: 0xdbfa5b0; frame = (0 0; 0 0); tag = 99; layer = <CALayer: 0xdbfa680>>
最佳答案
您可能正在注释上设置标签属性并尝试在注释 View 上读回它。
此外,您的代码片段似乎正在泄漏 annView
;你可能想自动释放它。
关于iphone - MK注释: Reading a tag for MKAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3685312/