I'm trying to put a little button in my AnnotationViews to show some info about some places on a map. Sounds super basic? Well. I must be an idiot then...
I've looked at multiple examples, searched the whole internet, and I have ripped of 95% of my hair. It just doesn't work!
-(MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)theAnnotation;
{
MKAnnotationView * annotationView = nil;
if([theAnnotation class] == [MyAnnotation class])
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:theAnnotation reuseIdentifier:@"annotation"];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.enabled = YES;
}
return annotationView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
{
NSLog(@"push %@", co开发者_StackOverflow社区ntrol);
}
Can some one please tell me why calloutAccessoryControlTapped never gets called? I get a nice and pretty annotation, but when I tap the blue button it just closes. I have tried adding a target to the button, nothing.
Please help me!
PS: I know I should reuse old annotation view and stuff, but i stripped all code that wasn't necessary to be sure that there wasn't something else that was screwing thins up.
Make sure you have correctly set the delegate
responding to the MKMapViewDelegate Protocol
.
Also, make sure that all the views and superviews have userInterActionEnabled
set to YES
.
精彩评论