I use this code for create my custom annotation view.
- (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;
}
My problem is how to send parameter to my selector: -showRestaurantDescription:
As I think I can add tag to the button and handle it, but I need best way to choose, because I have array with my restaurants and when I tap on concrete pin I need to show current restaurant. So the tags in this case not very convenient as I think.
You should use the delegate method
mapView:annotationView:calloutAccessoryControlTapped:to listen for taps on the button. That method gets passed anannotationViewwhich has anannotationproperty. You can use the annotation property to figure out which restaurant it was.Also, did you forget the colon in
action:@selector(showRestaurantDescription)?