viewForAnnotation返回nil
问题描述:
所以我已经实现了我的viewForAnnotation这样viewForAnnotation返回nil
- (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
答
实现了MKAnnotation
协议必须实现coordinate
属性的类。
infl8Node
类似乎不这样做,这就是为什么你会得到那个unrecognized selector
错误。
至少,该类将需要实现一个coordinate
方法,该方法返回与其位置关联的坐标。
实际上,该错误表示infl8Node类没有实现坐标属性。你可以发布infl8Node.h吗? – Anna
..并确保它#输入正确 –