首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKAnnotationView

MKAnnotationView
EN

Stack Overflow用户
提问于 2012-07-27 18:19:46
回答 1查看 405关注 0票数 0

我使用这段代码来创建我的自定义注释视图。

代码语言:javascript
复制
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {

    MKPinAnnotationView *pinAnnotation = nil;
    if(annotation != myMapView.userLocation) {
        static NSString *defaultPinID = @"myPin";
        pinAnnotation = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinAnnotation == nil )

            pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinAnnotation.canShowCallout = YES;

        //instatiate a detail-disclosure button and set it to appear on right side of annotation
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [infoButton addTarget:self
                       action:@selector(showRestaurantDescription)
             forControlEvents:UIControlEventTouchUpInside];
        pinAnnotation.rightCalloutAccessoryView = infoButton;
    }    
    return pinAnnotation;
}

我的问题是如何向选择器发送参数:-showRestaurantDescription:

因为我认为我可以添加标签到按钮并处理它,但我需要最好的选择方式,因为我有我的餐厅数组,当我点击混凝土别针时,我需要显示当前的餐厅。所以本例中的标签并不像我想的那样方便。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-27 18:58:11

您应该使用委托方法mapView:annotationView:calloutAccessoryControlTapped:来侦听按钮上的点击。该方法将传递一个具有annotation属性的annotationView。您可以使用注释属性来确定是哪个餐厅。

另外,您是否忘记了action:@selector(showRestaurantDescription)中的冒号

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11685875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档