Determine which MKPinAnnotationView was selected?

霸气de小男生 提交于 2019-12-11 19:17:57

问题


I place some custom MKPinAnnotationView on the map, with different information about landmarks (name, description, image, accessory button). When a user click and open one of the pins, and then click the accessory button inside it, I want to know which of the pins the user have clicked so I can load a viewcontroller with more detailed information.

I found these methods:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
}

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view   
{
}

... but how do I know which pin was selected? I would like to do something like:

   - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view   
    {
        //Example
        if ([view.description isEqualToString: @"Golden Gate"])
        {
             //Load golden gate information in a new viewcontroller
        }
    }

...but view.description won't give me the right information.

Thanks in advance


回答1:


If you're storing the name/description in the title/subtitle of your MKAnnotationView you can access these informations just by accessing to the annotation property of the MKAnnotationView:

if ([view.annotation.title isEqualToString: @"Golden Gate"])
   {
         //Load golden gate information in a new viewcontroller
   }


来源:https://stackoverflow.com/questions/10739335/determine-which-mkpinannotationview-was-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!