tags:

views:

598

answers:

3

My map pins can be quite densely populated so that when a pin is selected the callout pops up but is mostly obscured by all the other map pins - I can bring the Map Pin to the front it there were a delegate for selected map pin ( not tapped callout, selected pin ).

Any suggestions for a work around ?

+1  A: 

UICallout view is the subview of the MKAnnotationView. So, I think if you will bring Map ping to the front, UICAlloutView will be there too.

tt.Kilew
how do you bring the UICalloutView to the front programmatically?
blackkettle
A: 

This stackoverflow question answered me

http://stackoverflow.com/questions/1681565/z-ordering-of-mkannotationviews/1848874#1848874

Mugunth Kumar
+2  A: 

If you are using custom annotation views you can add an observer for the selected property which would act like a delegate for when the pin is selected.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    MKAnnotation *annview = ...code to either dequeue or create new object...
    [annview addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:@"selectedmapannotation"];               
    return annview;
}

then you can monitor the selected state with

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

The answer linked by Mugunth Kumar will also give you the desired results it's just that you made mention of delegate like functionality in your question.

EDIT:

Here is an example of the contents of the observeValueForKeyPath:ofObject:change:context: method

NSString *action = (NSString*)context;

if([action isEqualToString:@"selectedmapannotation"]){
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
    MKAnnotationView *ann = (MKAnnotationView *)object;

    if (annotationAppeared) {
        // do something with the annotation when it is selected
    }
    else {
        // do something with the annotation when it is de-selected
    }
}
acqu13sce
could you elaborate on this? what would the observeValueForKeyPath implementation actually look like? can you give an example?
blackkettle
edited the answer to add an example implementation, hope that helps!
acqu13sce