1

I am trying to use the CalloutAccessory feature, but the delegate method never gets called. I have the delegate properly set up as other mapview delegate methods in my code are firing fine, but for some reason for this one, the delegate method never gets called when the button is tapped.

I have tried extending RouteViewAnnotation from both the MKAnnotationView and the MKPinAnnotationView, and it makes no difference.. the delegate method never gets called.

What am I missing? Do I need something else that isn't here for this to work? The RouteAnnotationView just overrides the drawrect, and has no other code in it.

Relevant Code:

In ViewForAnnotation

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
if([annotation isMemberOfClass:[RouteAnnotation class]])
{
    RouteAnnotationView *routeAnnotationView = [[RouteAnnotationView alloc] initWithFrame:(CGRectMake(0,0,100,50))] ;
    [routeAnnotationView setBackgroundColor:[UIColor clearColor]];
    routeAnnotationView.centerOffset = CGPointMake(0,-25);
    routeAnnotationView.canShowCallout = TRUE;
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100.0, 40.0)];

    [button setTitle:@"Select" forState:UIControlStateNormal];

    button.backgroundColor = [UIColor blueColor];

    [routeAnnotationView setRightCalloutAccessoryView:button];

    return routeAnnotationView;

}
.
.
.
}

In calloutAccssoryControlTapped

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"CALLOUT BUTTON TOUCHED");
}
4

1 回答 1

2

好的,我想通了......我有一个分配给 MapView 的 tapGestureRecognizer(准确地说是一个 WildcardGestureRecognizer(https://github.com/OrbJapan/ResizableMKCircleOverlay/blob/master/MapView/WildcardGestureRecognizer.m))添加到我的MapView,虽然这并没有以任何方式干扰注释触摸,或者我正在使用的 MapView 或 MapView 委托方法中的其他触摸,但由于某种原因,这完全干扰了 calloutAccessoryControlTapped 委托方法,并且它从未被调用......一旦我删除了这个调用没有问题的方法。

于 2015-09-07T20:58:15.530 回答