问题
I have very new to MapKit Implementation
In my app one page is to be map View
in that I have displayed bulk amount of pins and their Annotation actions.
I have added a Discloser button on the popup bubble
and set action for these discloser buttons as shown bellow.
i Want to Same action When tap on that gray bubble
//To add a discloser button to show route map
UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView=detailBtn;
[detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
DisplayMap *ann=(DisplayMap *)annotation;
detailBtn.tag = ann.detailButtonTag;
//viewForAnnotation DELEGATE for annotions
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
//To add a discloser button to show route map
UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView=detailBtn;
[detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
DisplayMap *ann=(DisplayMap *)annotation;
detailBtn.tag = ann.detailButtonTag;
}
else
{
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
But i Want to Same action When tap on that gray bubble..
how to do it

回答1:
You have to use the following delegate method to get the tap on the bubble.
-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(id<GMSMarker>)marker
{
DetailViewController *Detail = [[DetailViewController alloc]initWithNibName:@" DetailViewController" bundle:nil];
Detail.data=marker.userData; // passing the data
[self.navigationController pushViewController:restDetail animated:YES];
}
回答2:
There are two methods for that in MKMapViewDelegate :
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
For more detail on how to use these methods, you can check the Answer by Rob.
Update :
For that you can use Custom Callout. You can create Custom Button with the "showRoute" methods and add as a Sub view to the Custom Callout Content View.
来源:https://stackoverflow.com/questions/18308031/how-to-add-action-selector-to-the-popup-bubble-on-annotation-view