MyAnnotationはMKAnnotationプロトコルを実装していません。
-
19-09-2019 - |
質問
私は、私はこれを使用するたび「MyAnnotationはMKAnnotationプロトコルを実装していません」という警告があります:
[mapView addAnnotation:annotation];
or
[mapView removeAnnotation:mapView.annotations];
誰かがアイデアを持っている?
解決
(あなたの注釈オブジェクトが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
所属していません StackOverflow