2010-03-12 46 views
1

我有一个警告“MyAnnotation没有实现MKAnnotation协议”每次我用这个:MyAnnotation没有实现MKAnnotation协议


[mapView addAnnotation:annotation]; 

or 

[mapView removeAnnotation:mapView.annotations]; 

有人有一个想法?

回答

3

(假设你注释对象是MyAnnotation类的实例)

的MKMapView要求其注释对象符合MKAnnotation协议,以确保他们实现某些必要的方法 - 否则你的应用程序可以产生运行时错误。该协议定义如下:

// MKAnnotation.h 
@protocol MKAnnotation <NSObject> 

// Center latitude and longitude of the annotion view. 
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 

@optional 

// Title and subtitle for use by selection UI. 
- (NSString *)title; 
- (NSString *)subtitle; 

@end 

那是你的MyAnnotation类必须定义和实现coordinate财产,也可以实现2种可选title方法。为了让编译器知道你的类实际上遵循的协议,你必须声明你的类的方式如下:当我尝试删除引脚是这里

@interface MyAnnotation: NSObject <MKAnnotation> // Or whatever parent class you have 
+0

感谢我的第一个警告现在不在这里,但第二次警告,它说:“NSArray没有实现MKAnnotation协议” – ludo

+0

- , - 我错误的忘记了 - 删除注释 – ludo