Pregunta

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.

¿Fue útil?

Solución

@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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top