簡體   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