0

Suppose I have an image saved on the iPhone, and a class I called MKAnnotationDelegate that implements the MKAnnotation protocol.

I can display annotations on an map view using that class, but can't figure out how to set a callout acccessory and put in an image.

So I've implemented the MKMapiewDelegate protocol to, and gave the class a UIImage property, and defined the

-(MKAnnotationView *) mapView:(MKMapView *)mapView 
            viewForAnnotation:(id<MKAnnotation>)annotation;

and I've put in these two lines:

annotationView.canShowCallout = YES;

[(UIImageView *)annotationView.rightCalloutAccessoryView setImage: _image];

but still can't figure out what to do to get the image in there .

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
user1542660
  • 1,299
  • 2
  • 9
  • 8
  • check my answer : http://stackoverflow.com/questions/4819006/iphone-sdk-mapkit-multiple-points-and-annotation/4826030#4826030 – HelmiB Jul 31 '12 at 03:23

3 Answers3

1
UIImageView *imageView = // init the image view ...
[imageView setImage:_image];
[annotationView setRightCalloutAccessoryView:imageView];

These are usually used to display UIButton.

runmad
  • 14,846
  • 9
  • 99
  • 140
0

This may help you, In a following method implementation:

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation;
{
// Initialize the MKPinAnnotationView...
UIImage *image = [UIImage imageNamed:@"imagename"];
UIImageView *imgView =[[UIImageView alloc] initWitthImage:image];
[annotationView setRighCalloutAccessoryView:imgView];
//or
[annotationView setLeftCalloutAccessoryView:imgView];

}

Something from Apple Docs on MKPinAnnotationView Class Reference:

rightCalloutAccessoryView The view to display on the right side of the standard callout bubble.

@property (retain, nonatomic) UIView *rightCalloutAccessoryView
Discussion

This property is set to nil by default. The right callout view is typically used to link to more detailed information about the annotation. The height of your view should be 32 pixels or less. A common view to specify for this property is UIButton object whose type is set to UIButtonTypeDetailDisclosure.

If the view you specify is also a descendant of the UIControl class, you can use the map view’s delegate to receive notifications when your control is tapped. If it does not descend from UIControl, your view is responsible for handling any touch events within its bounds.

Also refer leftCalloutAccessoryView property of MKPinAnnotationView

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Shanmugaraja G
  • 2,778
  • 4
  • 31
  • 47
0

you are set image only into RightCalloutAccessoryView and LeftCalloutAccessoryView into mapview annotation. If you want to set your view into annotation than you create own custom annotation.

Try this one example that add tableview into annotation view link.

iAndroid
  • 951
  • 7
  • 18