简体   繁体   English

异常'NSInvalidArgumentException',原因:'-[AnnotationView setCoordinate:]:无法识别的选择器已发送到实例

[英]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.

相关问题 由于未捕获的异常&#39;NSInvalidArgumentException&#39;而终止应用程序,原因:&#39;-[__ NSCFType next]:无法识别的选择器已发送至实例&#39; - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType next]: unrecognized selector sent to instance ' NSInvalidArgumentException || 无法识别的选择器已发送到实例 - NSInvalidArgumentException || Unrecognized selector sent to instance &#39;NSInvalidArgumentException&#39;/&#39;-[AppDelegate fieldChanged:]:无法识别的选择器已发送到实例 - 'NSInvalidArgumentException' / '-[AppDelegate fieldChanged:]: unrecognized selector sent to instance CoreData和NSInvalidArgumentException无法识别的选择器发送到实例 - CoreData and NSInvalidArgumentException unrecognized selector sent to instance iOS:“ NSInvalidArgumentException”,原因:“-[__ NSCFString sortedArrayUsingFunction:context:]:无法识别的选择器已发送到实例。 - iOS: 'NSInvalidArgumentException', reason: '-[__NSCFString sortedArrayUsingFunction:context:]: unrecognized selector sent to instance. 疯狂的MAPKit错误“ NSInvalidArgumentException”,原因:“ ***-[UISwipeGestureRecognizer removeFromSuperview]:无法识别的选择器已发送到实例 - Crazy MAPKit bug 'NSInvalidArgumentException', reason: '*** -[UISwipeGestureRecognizer removeFromSuperview]: unrecognized selector sent to instance &#39;NSInvalidArgumentException&#39;-[UIViewController tableView:numberOfRowsInSection:]-无法识别的选择器已发送到实例 - 'NSInvalidArgumentException' - [UIViewController tableView:numberOfRowsInSection:] - unrecognized selector sent to instance &#39;NSInvalidArgumentException&#39;:无法识别的选择器发送到实例0x8d25aa0&#39; - 'NSInvalidArgumentException': unrecognized selector sent to instance 0x8d25aa0' 无法识别的选择器发送到iOS7中的实例异常 - unrecognized selector sent to instance exception in iOS7 解析json并获取异常,原因:&#39;-[__ NSCFArray objectForKey:]:无法识别的选择器已发送到实例0x7b1c7630 - parsing json and getting exception, reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x7b1c7630
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM