views:

107

answers:

1

Hey all, I got somewhat of a dense question about the mapKit for the iPhone.

I'm using the MapKit framework and what I'm trying to do is basically click a pin, reload it and then show it's callOut after it has been added again.

This is the code I'm trying to get to work..

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    NSLog(@"count of selected Annotations: %d",[mapView selectedAnnotations].count);
    MKAnnotation* pin = view.annotation;
    [mapView deselectAnnotation:pin animated:FALSE];
    [mapView removeAnnotation:pin];
    [mapView addAnnotation:pin];
    [self.mapView selectAnnotation:pin animated:TRUE];

A few observations: If I comment the removeAnnotations and addAnnotation lines out, I enter an infinite loop because when I selectAnnotation:pin, the callback (which is this method) is called... otherwise, it isn't, but then what is? why isn't

[self.mapView selectAnnotation:pin animated:TRUE]; 

being called?

I've already read far too much and broke my head for far too many hours trying to figure this out that an explanation and a fix to my code would be much more helpful than a link.

Thanks in advance. ~Fydo

A: 

So I've answered my Own Question... it seems that the easiest way to change the annotation upon clicking it, is as follows:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    MKAnnotation* pin = view.annotation;
    UIImageView * blackPin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PinUnchecked.png"]];
   [[mapView viewForAnnotation:pin] addSubview:blackPin];

This delegate method will be called, then an annotationView bubble will be displayed AND the annotationView will change it's image... which is all I needed done...

Fydo