繁体   English   中英

如何跟踪单击了哪个注释标注

[英]How to track which annotation callout clicked

我使用以下代码创建带有右侧附件按钮的注释标注

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;
}

else {

    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
    }

    annotationView.image = [UIImage imageNamed:@"Mevents.png"];
    annotationView.annotation = annotation;
    annotationView.canShowCallout=YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];

    annotationView.rightCalloutAccessoryView = rightButton;

    //  UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
    //  pinView.leftCalloutAccessoryView = profileIconView;
    //  [profileIconView release];

    return annotationView;

}

}

如何跟踪单击了哪个注释 我想用ID加载详细信息屏幕,并根据该ID获取数据以显示信息。

创建注释时,在其中添加标签

annotationView.image = [UIImage imageNamed:@"Mevents.png"];
//Add this after
annotationView.tag = 111;

现在在viewForAnnotation ,检查该标签

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;

    if(annotation.tag == 111)
        //Do something
    else
        //Do some other thing
}

嘿兄弟在以下主题中检查我的答案,它可以为您提供帮助。

在mapview上点击注释时,将数据传递到detailView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM