嗨,我在 mapview ontap 中有 100 个注释,其中一个注释我应该得到与之相关的注释索引。有谁知道为此获取标签号?寻找任何委托方法都可以。
问问题
977 次
1 回答
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];
}
}
于 2016-01-12T11:12:13.407 回答