これを使用するたびに、「MyAnnotationはMKAnnotationプロトコルを実装していません」という警告が表示されます。
[mapView addAnnotation:annotation];
or
[mapView removeAnnotation:mapView.annotations];
誰かがアイデアを持っていますか?
これを使用するたびに、「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