[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType next]: unrecognized selector sent to instance '
[英]exception 'NSInvalidArgumentException', reason: '-[AnnotationView setCoordinate:]: unrecognized selector sent to instance
仅在Xcode 版本5.0中出现此错误
在Xcode 版本4.6.2中创建此应用之前,它对我来说运行良好,但是在Xcode 版本5.0中出现此错误。
我创建了自定义注释类,以生成更新的位置和地址。
我的代码是:
AnnotationView.h
#import <MapKit/MapKit.h>
@interface AnnotationView : MKPlacemark
@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subtitle;
@end
AnnotationView.m
#import "AnnotationView.h"
@implementation AnnotationView
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
{
self.coordinate = coordinate;
}
return self;
}
@end
以上是我的自定义课程。 我在MapView中使用了它。
CLLocationCoordinate2D theCoordinate ;
theCoordinate.latitude = [self.latitude doubleValue];
theCoordinate.longitude = [self.longitude doubleValue];
AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:theCoordinate addressDictionary:nil] ;
annotation.title = self.businessName;
annotation.subtitle = self.businessAddress;
[self.mapView addAnnotation:annotation];
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(theCoordinate, 8000, 8000)];
[self.mapView setRegion:adjustedRegion animated:YES];
请建议我在哪里出错。
AnnotationView
的超类(即MKPlacemark
)已经存储了coordinate
-请注意,您已将其传递到super initWithCoordinate:
方法中-因此您无需将coordinate
存储在子类中。 让超类处理它。
换句话说,您应该从AnnotationView
类中删除以下行:
self.coordinate = coordinate;
如果您需要从AnnotationView
访问coordinate
属性,只需使用[super coordinate]
。
请注意,使用您自己的具有相同名称的属性覆盖超类的属性-一般而言,您不希望这样做!
至于为什么在以前没问题的情况下在Xcode 5中遇到问题:这可能是因为不同版本的编译器对代码的解释略有不同。 您的代码总是有问题的,只是编译器现在注意到了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.