0

所以我已经实现了我的 viewForAnnotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *identifier = @"id";

if ([annotation isKindOfClass:[infl8Node class]]) {
    NSLog(@"Creating a pin");
    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;

    return annotationView;
}

return nil;
}

但是我仍然遇到这个错误:

2012-11-18 22:12:35.608 Infl8[5960:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[infl8Node coordinate]: unrecognized selector sent to instance 0x846f460'

有谁知道可能导致此错误的原因?我已经将其追溯到注释属于 MKUserLocation 类的情况。

编辑:这是 infl8Node.h 文件:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface infl8Node : NSObject <MKAnnotation>

@property (nonatomic, strong) NSString *accountName;
@property (nonatomic, strong) NSString *status;
@property (nonatomic, strong) CLLocation *location;
@property (nonatomic, strong) NSDictionary *address;

- (id) initWithDictionary:(NSDictionary *)dict;
- (MKMapItem *) mapItem;
@end
4

1 回答 1

0

实现MKAnnotation协议的类必须实现coordinate属性。

infl8Node课程似乎没有这样做,这就是您收到该unrecognized selector错误的原因。

至少,该类需要实现一个coordinate方法,该方法返回与其位置相关的坐标。

于 2012-11-19T03:36:41.240 回答