我想更改MKMapView上显示的标注。当我打电话
[self.mapView selectAnnotation:annotation animated:YES];
它将地图平移到注释,但不显示其标注。如何让它显示标注?
答案 0 :(得分:2)
在注释对象上设置title
和可选的subtitle
属性。 MapKit会自动显示标注。
@interface MyAnnotation : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
实施,
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize title, subtitle;
@end
用法,
MyAnnotation *foo = [[MyAnnotation alloc] init];
foo.title = @"I am Foo";
foo.subtitle = "I am jus' a subtitle";
答案 1 :(得分:0)
您应该实现MKAnnotation Delegate方法
-(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;
}