selectAnnotation不显示标注

| 我想更改MKMapView上显示的标注。当我打电话
[self.mapView selectAnnotation:annotation animated:YES]; 
它将地图平移到注释,但不显示其标注。如何显示标注?     
已邀请:
        在注释对象上设置
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\";
    
        您应该实现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;
}
    

要回复问题请先登录注册