How to find which annotation send showDetails?

后端 未结 1 1187
南旧
南旧 2020-11-30 15:32

How to find which annotation send showDetails?

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                                 


        
相关标签:
1条回答
  • 2020-11-30 16:19

    The comments in your code have the answer. Instead of using a custom method and calling addTarget, use the map view's calloutAccessoryControlTapped delegate method. In this method, you will get a reference to the annotation view which contains a reference to the annotation.

    Remove the call to addTarget and replace your "showDetails" method with:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
    {
        MyAnnotationClass *annot = (MyAnnotationClass *)view.annotation;
        //do something...
    }
    
    0 讨论(0)
提交回复
热议问题