地图注释索引号不断变化

Map annotation index number keep changing

我想在点击地图点时获取地图注释索引号,但我遇到了一个问题,那就是当我第一次 运行 应用程序并点击它显示索引的点时= 5。但是,当我重新 运行 应用程序并再次单击同一点时,它显示索引 = 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);
}

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

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