How to trigger MKAnnotationView's callout view without touching the pin?

后端 未结 13 2396
时光取名叫无心
时光取名叫无心 2020-11-29 19:57

I\'m working on a MKMapView with the usual colored pin as the location points. I would like to be able to have the callout displayed without touching the pin.

13条回答
  •  青春惊慌失措
    2020-11-29 20:16

    But there is a catch to get benvolioT's solution to work, the code

    for (id currentAnnotation in mapView.annotations) {       
        if ([currentAnnotation isEqual:annotationToSelect]) {
            [mapView selectAnnotation:currentAnnotation animated:FALSE];
        }
    }
    

    should be called from - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView, and nowhere else.

    The sequence in which the various methods like viewWillAppear, viewDidAppear of UIViewController and the - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView is called is different between the first time the map is loaded with one particular location and the subsequent times the map is displayed with the same location. This is a bit tricky.

提交回复
热议问题