繁体   English   中英

MKAnnotation:读取MKAnnotation的标签

[英]MKAnnotation: Reading a tag for MKAnnotation

添加注释时,会在其中添加“ .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>>

您可能会在注释上设置tag属性,并尝试在注释视图上读回它。

另外,您的代码段似乎正在泄漏annView 您可能要自动释放它。

暂无
暂无

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

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