0

I am developing an application in iphone which deals with maps. I have many annotations. I need different images to be loaded in the callout(left accessory view) for each of these annotations. Can anyone please tell me how to do this. The user adds annotations dynamically when needed and chooses a image from the gallery to add it to that particular annotation callout. I am able to add images to callouts. but not able to differentiate it for different annotations

Droidme
  • 1,223
  • 6
  • 25
  • 45

1 Answers1

0

Set the leftCalloutAccessoryView in your viewForAnnotation: method of the Map. The leftCallout is a UIView so you can put anything there. Some sample code might look like:

        MKAnnotationView *av = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                 reuseIdentifier:@"ReuseMe"] autorelease];
        [av setCanShowCallout:YES]; 
        UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SFIcon.png"]];
        av.leftCalloutAccessoryView = sfIconView;
        [sfIconView release];  

Review the MapCallouts demo code from Apple. It does what you want.

UPDATE BASED on Comment: to change out the image just put in a new image in initWithImage. you could have the line be something like

UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[myArrayOfImages objectAtIndex:myIndexVariable]];

You could even refactor the lines that start UIImageView all the way to [sfIconView and pass in the image that way. The code for viewForAnnotation: gets called one time for each annotation (just like the cells in a UITableView).

Walter
  • 5,867
  • 2
  • 30
  • 43
  • Thnaks for answering quickly.I have gone through that tutorial. I am able to add images to callouts. But I wan to add different images to each of them The user chooses a image from the gallery for a particular annotation. Then that image shows up oly for that annotation. hope its clear. plz help. – Droidme Mar 14 '11 at 12:37
  • The user can also add new annotations on the map. hence new images. – Droidme Mar 14 '11 at 12:41
  • I am not able to achieve the result. I have already included them. May I know how to use the "reuse" keyword which u have mentioned in ur code. – Droidme Mar 14 '11 at 13:35
  • @Droidme post your viewForAnnotation: code in your original question. Also, add the variable that is holding the image and I will help you modify the code. – Walter Mar 14 '11 at 13:55