質問

私は、私はこれを使用するたび「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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top