我可以在单击 PIN 时打开方法,但我想在按下此 BLACK POP UP 时调用方法,而不是 PIN。
我该怎么做?
尝试添加rightCalloutAccessoryView
喜欢
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString * identifier = @ "pinId" ;
MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier ];
if ( !pin &&(annotation != mapView.userLocation))
{
pin = [ [ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:identifier ];
pin.image = [UIImage imageNamed: @"g_pin.png" ];
pin.canShowCallout = YES;
pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
pin.annotation = annotation;
return pin;
}
你会在右上角得到一个按钮,比如
在点击此按钮时,将调用此方法
- (void)mapView:(MKMapView *)_mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"Pin Tapped");
}
这将帮助你.....享受
使用两个委托方法
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view