如何找到哪个注释发送showDetails? [英] How to find which annotation send showDetails?

查看:152
本文介绍了如何找到哪个注释发送showDetails?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到哪个注释发送showDetails?

How to find which annotation send showDetails?

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                             initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
            customPinView.pinColor = MKPinAnnotationColorPurple;
            customPinView.animatesDrop = YES;
            customPinView.canShowCallout = YES;

            // add a detail disclosure button to the callout which will open a new view controller page
            //
            // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement:
            //  - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
            //
            UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [rightButton addTarget:self
                            action:@selector(showDetails:)
                  forControlEvents:UIControlEventTouchUpInside];
            customPinView.rightCalloutAccessoryView = rightButton;

            return customPinView;

- (void)showDetails:(id)sender
{
  some code
}


推荐答案

代码中的注释有答案。不使用自定义方法并调用addTarget,而是使用map视图的calloutAccessoryControlTapped委托方法。在此方法中,您将获得对注释视图的引用,该注释视图包含对注释的引用。

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.

删除对addTarget的调用并将showDetails方法替换为:

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...
}

这篇关于如何找到哪个注释发送showDetails?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆