0

I'm working with MapQuest but I think that is not the problem.

I have map (with MapQuest) and custom pins on it. I can tap the pins and my custom callout (xib-file with labels and one button) pops up and everything is working fine. The only problem is that I can't press the button on the custom callout view (UIView).

Here is my code:

-(MQAnnotationView*)mapView:(MQMapView *)aMapView viewForAnnotation:(id<MQAnnotation>)annotation {

    static NSString* identifier = @"Pins";
    MQAnnotationView * annotationView = (MQAnnotationView *)[self->mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    annotationView = [[MQAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    annotationView.image = [UIImage imageNamed:@"marker_schuhe"];

    annotationView.enabled = YES;
    annotationView.canShowCallout = NO;

    return annotationView;
}

And in my didSelectAnnotationView method:

- (void)mapView:(MQMapView *)mapView didSelectAnnotationView:(MQAnnotationView *)view {
        callOutView *calloutView = (callOutView *)[[[NSBundle mainBundle] loadNibNamed:@"callOutView" owner:self options:nil] objectAtIndex:0];
    CGRect calloutViewFrame = calloutView.frame;
    calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
    calloutView.frame = calloutViewFrame;

   [calloutView.my_button addTarget:self action:@selector(button_pressed:) forControlEvents:UIControlEventTouchUpInside]; //here is something wrong, button_pressed is never called

[view addSubview:calloutView];
}

1 Answers1

0

Set userInteractionEnabled = YES;on the calloutView?

calloutview

-- edit after comment from user

If @selector isn't working (because the MKAnotationView intercepts it) try adding a UIGesture to your UIButton like this:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] 
            initWithTarget:self action:@selector(button_pressed:)];
        tap.numberOfTapsRequired = 1;
        [calloutView.my_button addGestureRecognizer:tap];
Michael
  • 997
  • 1
  • 7
  • 13
  • Thanks Michael but your suggestion didn't work. The calloutView and the button are both visible but the button is not clickable. When I tap the whole calloutView the map is zooming in. Maybe here is the main problem? – Florian Thürkow Jul 09 '14 at 07:33
  • Hi Michael, the UIGesture didn't work. Maybe the button.frame is outside of the UIView? I can see my subview with the button (here is the screen) http://s30.postimg.org/r73zxx7up/IMG_1566.png the button on the right ">" is not clickable and I absolutely don't know why. – Florian Thürkow Jul 10 '14 at 08:18