[英]exception 'NSInvalidArgumentException', reason: '-[AnnotationView setCoordinate:]: unrecognized selector sent to instance
This error only seem in Xcode Version 5.0 仅在Xcode 版本5.0中出现此错误
Before i created this my app in Xcode Version 4.6.2 , it was working very well for me, but i got this error in Xcode Version 5.0 在Xcode 版本4.6.2中创建此应用之前,它对我来说运行良好,但是在Xcode 版本5.0中出现此错误。
I created custom Annotation class for generate my updated location and address. 我创建了自定义注释类,以生成更新的位置和地址。
My Code Is : 我的代码是:
AnnotationView.h 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 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
Above is my custom class. 以上是我的自定义课程。 I used it in my MapView. 我在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];
Please suggest me where i make mistake. 请建议我在哪里出错。
The superclass of your AnnotationView
, which is MKPlacemark
, already stores the coordinate
- note that you pass it into the super initWithCoordinate:
method - so you don't need to store the coordinate
in your subclass. AnnotationView
的超类(即MKPlacemark
)已经存储了coordinate
-请注意,您已将其传递到super initWithCoordinate:
方法中-因此您无需将coordinate
存储在子类中。 Let the superclass handle it. 让超类处理它。
In other words, you should remove this line from your AnnotationView
class: 换句话说,您应该从AnnotationView
类中删除以下行:
self.coordinate = coordinate;
If you need to access the coordinate
property from your AnnotationView
, just use [super coordinate]
. 如果您需要从AnnotationView
访问coordinate
属性,只需使用[super coordinate]
。
Be careful about overriding the properties of superclasses with your own property with the same name - generally speaking, you don't want to do this! 请注意,使用您自己的具有相同名称的属性覆盖超类的属性-一般而言,您不希望这样做!
As for why you are getting problems in Xcode 5 when it was ok before: this could be because a different version of the compiler is interpreting the code slightly differently. 至于为什么在以前没问题的情况下在Xcode 5中遇到问题:这可能是因为不同版本的编译器对代码的解释略有不同。 Your code was always problematic, it's just that the compiler is now noticing a problem with it. 您的代码总是有问题的,只是编译器现在注意到了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.