iphone - MKAnnotationView 并将数据传递给另一个函数

标签 iphone cocoa-touch mkmapview mkannotation mkannotationview

实际上,我正在我的应用程序中开发一些东西,它可以在我的 MKMapView 中显示注释这些注释应该是可单击的并将参数传递给方法。
现在的问题是如何在点击披露按钮时将参数传递给下一个函数。
对于注释的格式,我使用 - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation显示公开按钮的方法。但问题是,如何从 Annotation 中获取值当前显示的对象是什么?

我的代码为Annotation (仅相关部分):

@synthesize coordinate, id, title, subtitle;

+ (id)annotationWithCoordinate:(CLLocationCoordinate2D)coordinate {
    return [[[[self class] alloc] initWithCoordinate:coordinate] autorelease];
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
    self = [super init];

    if(nil != self) {
        self.coordinate = coordinate;
    }

    return self;
}

当触摸公开按钮时,方法- (void)displayInfo:(NSNumber *) anId;应该在移交时调用 Annotation.id作为anId参数。

披露按钮是使用该代码生成的:

   UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    dropPin.rightCalloutAccessoryView = disclosureButton;
    dropPin.animatesDrop = YES;
    dropPin.canShowCallout = YES;

所以 - 问题:
我如何将该参数传递给函数或读取 id点击的Annotation

我认为我可以使用 UIButton 的选择器(但是 - 如何传递 id?)或使用 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 来处理 discoveryButton 上的点击。 (再次 - 如何传递 id?)。

我希望您明白我的意思,非常感谢您的回答! :)

最佳答案

在 calloutAccessoryControlTapped 中,注释可通过 View 获得:

MKAnnotation *annotation = view.annotation;

关于iphone - MKAnnotationView 并将数据传递给另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4509663/

相关文章:

ios - 如何在 DJI-UXSDK-demo 中添加工作 slider 到 map View

iphone - 如何显示从最新到最旧排列的相册

iOS 在使用 ffmpeg 添加的音频和字幕轨道之间切换

iPhone master detail app如何使用detail view更改master view中对应单元格显示的文本值

iphone - 使用 UISearchBar 关闭键盘,而不放弃第一响应者

iOS 5.1 UIView调用 super ViewController的选择器

ios - 给mkmap添加注解,想去掉部分注解却不会去掉

ios - 以编程方式显示 iPhone 键盘

ios - 如何在 UITableview 中使用两个自定义单元格

ios - 如何更改我的 MKMapView 注释的外观