views:

635

answers:

1

Hi,

I have a warning "MyAnnotation does not implement the MKAnnotation protocol" everytime I use this:


[mapView addAnnotation:annotation];

or

[mapView removeAnnotation:mapView.annotations];

Someone have an idea?

+3  A: 

(Assumed that you annotation object is an instance of MyAnnotation class)

MKMapView require that its annotation objects conform to MKAnnotation protocol to ensure they implement certain required methods - otherwise your application can produce errors in run-time. This protocol is defined as follows:

// 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

That is your MyAnnotation class must define and implement coordinate property and may also implement 2 optional title methods. To let compiler know that your class actually conforms to a protocol you must declare your class the following way:

@interface MyAnnotation: NSObject <MKAnnotation> // Or whatever parent class you have
Vladimir
thanks my first warning not here now, but the second warning when I try to remove Pins is here and it say: "NSArray does not implement the MKAnnotation protocol"
ludo
-,.- my mistake I just forget to put -s to removeAnnotations
ludo