MyAnnotation nicht implementiert das Protokoll MKAnnotation
-
19-09-2019 - |
Frage
Ich habe eine Warnung jedes Mal „MyAnnotation nicht das MKAnnotation Protokolls nicht implementiert“ Ich verwende:
[mapView addAnnotation:annotation];
or
[mapView removeAnnotation:mapView.annotations];
Jemand eine Idee?
Lösung
(vorausgesetzt, dass Sie Anmerkungsobjekt ist eine Instanz der Klasse MyAnnotation)
MKMapView verlangt, dass seine Annotation Objekte MKAnnotation
Protokoll entsprechen sie bestimmte erforderliche Methoden, um sicherzustellen, implementieren - ansonsten Ihre Anwendung kann Fehler in der Laufzeit erzeugen. Dieses Protokoll wird wie folgt definiert:
// 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
Das ist Ihre MyAnnotation Klasse muss definieren und coordinate
Eigenschaft implementieren und auch 2 optionale title
Methoden implementieren können. Um Compiler wissen zu lassen, dass Ihre Klasse Konform tatsächlich auf ein Protokoll, das Sie Ihre Klasse die folgende Art und Weise erklären müssen:
@interface MyAnnotation: NSObject <MKAnnotation> // Or whatever parent class you have