我使用这段代码来创建我的自定义注释视图。
- (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:
因为我认为我可以添加标签到按钮并处理它,但我需要最好的选择方式,因为我有我的餐厅数组,当我点击混凝土别针时,我需要显示当前的餐厅。所以本例中的标签并不像我想的那样方便。
发布于 2012-07-27 18:58:11
您应该使用委托方法mapView:annotationView:calloutAccessoryControlTapped:来侦听按钮上的点击。该方法将传递一个具有annotation属性的annotationView。您可以使用注释属性来确定是哪个餐厅。
另外,您是否忘记了action:@selector(showRestaurantDescription)中的冒号
https://stackoverflow.com/questions/11685875
复制相似问题