Question

Im creating an app that uses uimap - IOS app . I have created a callout annotation that loads from a nib file and adds it as subview. now i'have added a button in the nib file and I cant get an event when clicking the button in the subview.

how can I make an event when the button in the subview is clicked ?

Thanks.

Was it helpful?

Solution

@implementation YourViewController

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    CalloutView *calloutView = however you load it from nib;
    calloutView.button.tag = some unique id;
    [button addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
    return calloutView;
}

- (void)showDetails:(UIButton *)sender
{
    NSLog(@"Button tag: %i was pressed", sender.tag);
}
@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top