【问题标题】:How to know annotation index MKMapview ios如何知道注释索引MKMapview ios
【发布时间】:2016-01-12 08:43:15
【问题描述】:

嗨,我在 mapview ontap 中有 100 个注释,其中一个注释我应该得到与此相关的 注释索引。 有谁知道为此获取标签号? 寻找任何委托方法都可以。

【问题讨论】:

  • 表示你想为每个注释分配唯一的标签?
  • 在向 MapView 添加注释的地方添加代码 sn-p。
  • 我不想分配。如果用户单击注释,我已经显示注释需要获取索引值。

标签: objective-c iphone methods mkmapview mkmapviewdelegate


【解决方案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];
    }
}

【讨论】:

    猜你喜欢
    • 2011-07-27
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多