views:

1940

answers:

2

Hi,

I am using a m MKMapView containing a couple of MKAnnotation pins. Above the map I am showing a UITable with detailed information of the MKAnnotation pins.

My problem: When i select a pin , i would like to select the corresponding table cell. For this I would like to catch a event/delegate if the pin is selected. I am not talking about calling the callout accessory

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

Thanks in advance

+1  A: 

I haven't seen a simple way to do this in MapKit. There's no mapView:annotationWasTapped: on the delegate.

One way to do it would be to provide your own annotation view subclass. The custom annotation view could capture the pin selection in setSelected:animated: or in a lower level event handler and pass that information up to your view controller.

Will Harris
Oh, sounds good and seems not to be much work!Thank you!
squeezer123
This is the way I was doing it as well. Strange that Apple didn't provide any callback for that :/
yonel
+1  A: 

you can use an Observer for Selected-Event:

[pin addObserver:self
      forKeyPath:@"selected" 
         options:NSKeyValueObservingOptionNew
         context:@"ANSELECTED"];


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{

    NSString *action = (NSString*)context;

    if([action isEqualToString:@"ANSELECTED"]){

     BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
     if (annotationAppeared) {
      // clicked on an Annotation
     }
     else {
      // Annotation disselected
     }
    }
}
iPortable