代码之家  ›  专栏  ›  技术社区  ›  Oh Danny Boy

MKAnnotation:读取MKAnnotation的标记

  •  2
  • Oh Danny Boy  · 技术社区  · 14 年前

    当我添加注释时,我会添加一个“.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>>
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   rpetrich    14 年前

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

    annView