0

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

- (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:

因为我认为我可以将标签添加到按钮并处理它,但我需要最好的选择方式,因为我的餐厅有阵列,当我点击混凝土别针时,我需要显示当前餐厅。所以这种情况下的标签不像我想的那样方便。

4

1 回答 1

2

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

另外,你忘了冒号action:@selector(showRestaurantDescription)吗?

于 2012-07-27T10:58:11.497 回答