views:

1381

answers:

3

I'd like to a-synchronically load images for my custom MKAnnotationView; I'm already using the EGOImageView-framework (it goes very well with UITableViews), but I fail to make it work on MKMapView. Images seem to be loaded, but I cannot refresh them on the map - [myMap setNeedsDisplay] does nothing.

A: 

I haven't tried it myself, but it might work:
Get a view for annotation using MKMapView - (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation method and set new image to it.

Edit: Tried to do that myself and this approach worked fine for me:

//  Function where you got new image and want to set it to annotation view
for (MyAnnotationType* myAnnot in myAnnotationContainer){
 MKAnnotationView* aView = [mapView viewForAnnotation: myAnnot];
 aView.image = [UIImage imageNamed:@"myJustDownloadedImage.png"];
}

After calling this method all annotations images were updated.

Vladimir
that's how it's done now. But this way image is loaded synchronically.
Konstantin
And if you call it after the image is loaded and set this image to the view - doesn't it work?
Vladimir
that's the question - how to set this image later. By doing so, image gets not updated on the MKAnnotationView
Konstantin
As I've written - MKMapView allows you to obtain a view for any annotation. See in edited answer how it can be used.
Vladimir
A: 

I couldn't add a comment so i am usign the answer box -

What is the myAnnotationContainer in your code? is it the MKAnnotationViewContainer? How do you get that?

Dave
A: 

This is the only way I've found to force redraw of MKAnnotationViews:

// force update of map view (otherwise annotation views won't redraw)

CLLocationCoordinate2D center = mapView.centerCoordinate;

mapView.centerCoordinate = center;

Seems useless, but it works.

ZeroDiv