How to know annotation index MKMapview ios

删除回忆录丶 提交于 2020-01-17 06:20:52

问题


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.


回答1:


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.

But need to rewrite code as below

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


来源:https://stackoverflow.com/questions/34738995/how-to-know-annotation-index-mkmapview-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!