2016-01-12 30 views
0

您好,我在其中一個註解的mapview ontap中有100個註釋,我應該得到註釋索引與此相關。 有沒有人有想法獲得標籤號碼? 尋找任何委託方法。如何知道註解索引MKMapview ios

enter image description here

+0

意味着你想唯一的標籤分配給每一個註釋? –

+0

添加您向MapView添加註釋的代碼片段。 –

+0

我不想分配。如果用戶單擊註釋,我已經顯示註釋需要獲取索引值。 – Nagarjun

回答

1

找到了答案,這將返回註釋抽頭數:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    NSUInteger index = [mapView.annotations indexOfObject:view.annotation]; 
    NSLog(@"index no %d",index); 
} 

上面的代碼將生成隨機指數每次我們上標註挖掘時間。

但需要重寫代碼如下

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { 
    // Annotation is your custom class that holds information about the annotation 
    if ([view.annotation isKindOfClass:[Annotation class]]) { 
     Annotation *annot = view.annotation; 
     NSInteger index = [self.arrayOfAnnotations indexOfObject:annot]; 
    } 
} 
相關問題