【问题标题】:Map annotation index number keep changing地图标注索引号不断变化
【发布时间】:2017-06-30 03:03:41
【问题描述】:

我想在单击地图点时获取地图注释索引号,但我遇到了一个问题,即当我第一次运行应用程序并单击显示索引 = 5 的点时。但是当我重新运行应用程序并再次单击同一点,它显示 index = 23。在我重新运行应用程序后,索引号不断变化,它不会在我单击的确切点显示相同的索引号。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
        if ([view.annotation isKindOfClass:[MKPointAnnotation class]]) {

            NSUInteger index = [mapView.annotations indexOfObject:view.annotation];
            NSLog(@"Index number is %lu", (unsigned long)index);
}

【问题讨论】:

标签: ios objective-c annotations mkmapview mkannotationview


【解决方案1】:

我找到了解决方案,我将位置 ID 保存到 annotation.title 之后,我使用下面的代码来替换索引号。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
        if ([view.annotation isKindOfClass:[MKPointAnnotation class]]) {
           NSString *hubIden = view.annotation.title;
       }
}

【讨论】:

    猜你喜欢
    • 2017-07-04
    • 1970-01-01
    • 2014-09-14
    • 2020-11-05
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    相关资源
    最近更新 更多