如何知道标注索引MKMapview iOS [英] How to know annotation index MKMapview ios

查看:88
本文介绍了如何知道标注索引MKMapview iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mapview中有100个注释,其中一个注释应该与之相关的注释索引. 有谁知道获得标签号的想法吗? 寻找任何委托方法.

Hi i have 100 annotations in mapview ontap of one of its annotations i should get annotation index related to that. Does anyone have idea about getting tag number for that? Looking for any delegate method does.

推荐答案

找到了一个答案,该答案将返回标注的编号:

Found an answer this will return annotation tapped number:

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

上面的代码每次我们点击注释时都会生成随机索引号.

The above code will generate random index number each time we tap on annotation.

但是需要按如下所示重写代码

- (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];
    }
}

这篇关于如何知道标注索引MKMapview iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆