开发者

MKAnnotation: Reading a tag for MKAnnotation

开发者 https://www.devze.com 2023-01-16 04:07 出处:网络
When I add an annotation, I add a \".tag\" to it. However I can never read the tag in the following method.

When I add an annotation, I add a ".tag" to it. 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?

It is worth mentioning that if I NSLog annotation, I do see the tag.

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.

Also, it looks like your code snippet is leaking annView; you may want to autorelease that.

0

精彩评论

暂无评论...
验证码 换一张
取 消