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