darkman
darkman

Reputation: 1003

Click inside custom callout view MKMapView

I have a custom calloutview, which is called when the user taps inside a MKannotationView

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
//    NSInteger indexOfTheObject = [self.mapView.annotations indexOfObject:view.annotation];
    
    if([view.annotation isKindOfClass:[Estabelecimento class]])
    {
        CalloutView *calloutView = [[CalloutView alloc]initWithFrame:CGRectMake(0, 0, 230, 100)];
        [calloutView setDelegate:self];
        CGRect calloutViewFrame = calloutView.frame;
        calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
        calloutView.frame = calloutViewFrame;
        [calloutView.calloutTitleLabel setText:[(Estabelecimento*)[view annotation] title]];
        [calloutView.calloutEndLabel setText:[(Estabelecimento *)[view annotation] subtitle]];
        
        [view addSubview:calloutView];
    }
}

But, I can't track when the user click inside that view, already. This code is inside the custom calloutview

UIButton * interactionButton = [UIButton buttonWithType:UIButtonTypeCustom];
[interactionButton setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[interactionButton addTarget:self action:@selector(clickedInside:) forControlEvents:UIControlEventTouchUpInside];
[interactionButton setBackgroundColor:[UIColor clearColor]];
[self addSubview:interactionButton];

[self setUserInteractionEnabled:YES];

-(void)clickedInside:(id)tap
{
    NSLog(@"clicked inside");
}

The method is never called, already tried doing a UITapGestureRecognizer in that view, and doesn't work as well. It is possible to track that user interaction?

Upvotes: 2

Views: 289

Answers (0)

Related Questions