マップに注釈を表示し、そのうちの 1 つを選択したいと考えています。
- (void)someWebServiceCallbackWithResult:(NSDictionary *)mapPins {
[mapView removeAnnotations:mapView.annotations];
[mapView addAnnotations:[mapPins allValues]];
for (Pin *p in [mapPins allValues]) {
if ([p.name isEqualTo:@"Cafe-Derp"] && mapView.hidden == NO) {
//selectedMapAnnotationView is returned as nil at this point
MapAnnotationView *selectedMapAnnotationView = (MapAnnotationView *)[mapView viewForAnnotation:p];
[self presentPopover:p inMapAnnotationView:selectedMapAnnotationView];
}
}
}
ただしviewForAnnotation:
、if ステートメントでは nil を返します。
addAnnotations:
マップ上のすべてのピンを自動的に表示する必要があるため、これは発生しないはずです。viewForAnnotation:
このコードは、次のように呼び出す前に一定時間待機した場合にのみ機能します。
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
MapAnnotationView *selectedMapAnnotationView = (MapAnnotationView *)[mapView viewForAnnotation:p];
[self presentPopover:p inMapAnnotationView:selectedMapAnnotationView];
});
これはなぜですか?マップ ビューに、更新をトリガーするために呼び出す必要があるメソッドはありますか?