0

我有一个实现 MKAnnotation 协议的对象:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface VoiceMemoryAnnotation : NSObject <MKAnnotation> {
    NSString * blobkey;
}
@property (nonatomic, retain) NSString * blobkey;

-(id)initWithBlobkey:(NSString *) key andCoordinate:(CLLocationCoordinate2D) c;
@end

将这个对象添加到地图上效果很好,因为我可以看到红色的大头针被丢弃了。但是,当我想将此对象设置为显示标注时,就会出现问题。

我不能做 annotation.showCallOut=YES 因为“MkAnnotation”没有这个属性,但 MkAnnotationView 有。我该如何解决这个问题?

我尝试实现地图回调“viewForAnnotation”以检查“VoiceMemoryAnnotation”,并尝试返回一个新的“MkAnnotationView”并将其设置为 callout = YES,但是当我这样做时开始出现分段错误。

任何想法我做错了什么?

4

2 回答 2

2

首先,您需要创建您的注释对象(实现 MKAnnotation 协议的对象)并使用类似的东西将其添加到您的地图中

VoiceMemoryAnnotation*VMA = [[VoiceMemoryAnnotation alloc] init];
VMA.title = @"Title String";
VMA.subtitle = @"Subtitle String";

[self.mapView addAnnotation:VMA];

这将自动调用您需要实现的以下方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
 {
     MKPinAnnotationView*singleAnnotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:nil];
     singleAnnotationView.canShowCallout = YES;

     return singleAnnotationView;
 }

在这个实现中 MKAnnotationView 不起作用,它需要是 MKPinAnnotationView。

于 2012-03-11T04:28:11.220 回答
0

我不确定我是否完全理解你的问题,但我想知道,这是MKMapViews- (void)selectAnnotation:(id <MKAnnotation>)annotation animated:(BOOL)animated要找的吗?

于 2012-03-11T05:44:15.707 回答