我正在尝试使用 MKAnnotationView 中的“selected”属性(在此处讨论),这是为了让用户能够删除选定的注释......
以下代码应该在 MKMapView 中找到选定的引脚并将其删除:
CSMapAnnotation *a;
for(a in [mapView annotations])
{
if([a selected]) //Warning: 'CSMapAnnotation' may not respond to '-selected'
{
[mapView removeAnnotation:a];
}
}
其中 CSMapAnnotation 是我的自定义地图注释,定义如下:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
// types of annotations for which we will provide annotation views.
typedef enum {
kCMapAnnotationTypeStart = 0,
kCMapAnnotationTypeCheckpoint = 1,
kCMapAnnotationTypeEnd = 2
} CSMapAnnotationType;
@interface CSMapAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
CSMapAnnotationType annotationType;
NSString* title;
NSString* userData;
}
-(id) initWithCoordinate:(CLLocationCoordinate2D)inCoordinate
annotationType:(CSMapAnnotationType) annotationType
title:(NSString*)title;
- (BOOL) isEqualToAnnotation:(CSMapAnnotation *) anAnnotation;
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
@property (nonatomic, readwrite) CSMapAnnotationType annotationType;
@property (nonatomic, retain) NSString* title;
@property (nonatomic, retain) NSString* userData;
我认为因为我不是真正“继承”自MKAnnotationView
,CSMapAnnotation
所以不会回应selected
。
解决此问题的最佳方法是什么?