简体   繁体   English

MKAnnotation:读取MKAnnotation的标签

[英]MKAnnotation: Reading a tag for MKAnnotation

When I add an annotation, I add a ".tag" to it. 添加注释时,会在其中添加“ .tag”。 However I can never read the tag in the following method. 但是,我永远无法通过以下方法读取标签。

`- (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;
}

The NSLog is always 0. Can anyone shed some light on this? NSLog始终为0。有人可以对此加以说明吗?

It is worth mentioning that if I NSLog annotation, I do see the tag. 值得一提的是,如果我使用NSLog注释,则可以看到该标签。

2010-09-10 10:21:27.612 [1328:207] annotation = <BarPin: 0xdbfa5b0; frame = (0 0; 0 0); tag = 99; layer = <CALayer: 0xdbfa680>>

Likely you are setting the tag property on the annotation and trying to read it back on the annotation view. 您可能会在注释上设置tag属性,并尝试在注释视图上读回它。

Also, it looks like your code snippet is leaking annView ; 另外,您的代码段似乎正在泄漏annView you may want to autorelease that. 您可能要自动释放它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM