MKAnnotationView

问题描述:

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

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

当我想到我可以添加标签按钮,处理它,但我需要选择最好的方法,因为我有与我的餐厅阵列,当我点击具体的针我需要显示当前的餐厅。所以在这种情况下,标签不是很方便,因为我认为。

您应该使用委托方法mapView:annotationView:calloutAccessoryControlTapped:来侦听按钮上的按钮。该方法通过了一个annotationView,其中有一个annotation属性。您可以使用注释属性来确定它是哪家餐馆。

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