Reputation: 2489
I want to change the callout shown on the MKMapView. When I call
[self.mapView selectAnnotation:annotation animated:YES];
it pans the map to the annotation, but does not show its callout. How do I get it to show the callout?
Upvotes: 2
Views: 1598
Reputation: 1965
You should implement the MKAnnotation Delegate method
-(MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *AnnotationViewIdentifier = @"AnnotationViewIdentifier";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewIdentifier];
if (annotationView == nil)
{
annotationView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationViewIdentifier]autorelease];
}
annotationView.canShowCallout = YES;
return annotationView;
}
Upvotes: 0
Reputation: 141879
Set the title
, and optionally the subtitle
property on the annotation object. MapKit will automatically show a callout.
@interface MyAnnotation : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
And the implementation,
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize title, subtitle;
@end
Usage,
MyAnnotation *foo = [[MyAnnotation alloc] init];
foo.title = @"I am Foo";
foo.subtitle = "I am jus' a subtitle";
Upvotes: 2