开发者

Detecting which MKAnnotation callout was touched

I'm using MKMapKit to show some search results on a map. I'm using

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

to check when a callout has been pressed, but the only information I'm able to get is the view.annotation.title. This is of no use to me as I might have many results with the same title.

I've added an 开发者_JAVA技巧business_id property to the class, but I don't seem to be able to read it in this method. I'm guessing that this method is only for elements that are part of the View?

What's the best way of uniquely identifying which callout was touched?

Thanks.


Since the annotation is one of your making you can do with it what you will.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    MyGroovyAnnotation *annotation = (MyGroovyAnnotation *)view.annotation;
    id businessId = annotation.businessId;
    // do something remarkable
}

This will blow up if you copy and paste it as the method is called for any annotation view that is touched so you should check if the annotation view is the one with your custom annotation before sending messages to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜