MKMapview如何知道标注索引ios
How to know annotation index MKMapview ios
您好,我在 mapview ontap 中有 100 个注释,其中一个注释我应该得到与之相关的 annotation index。
有没有人知道为此获取标签号?
寻找任何委托方法。
找到一个答案这将return 批注点按数量:
- (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];
}
}
您好,我在 mapview ontap 中有 100 个注释,其中一个注释我应该得到与之相关的 annotation index。 有没有人知道为此获取标签号? 寻找任何委托方法。
找到一个答案这将return 批注点按数量:
- (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];
}
}