我正在尝试制作一个自定义 MKAnnotation 类,以便它可以保存其他信息,但我不断收到此错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [AnnotationForId setCoordinate:]: unrecognized selector sent to instance 0x16f63340'
我已经尝试查找如何创建一个,并且我已经按照我在网上找到的内容进行了操作,但我对为什么我不断收到此错误感到困惑。
这是我的自定义注释类。
#import <MapKit/MapKit.h>
#import <UIKit/UIKit.h>
@interface AnnotationForId : NSObject <MKAnnotation >{
NSString *title;
NSString *subtitle;
CLLocationCoordinate2D coordinate;
NSInteger shopId;
}
@property(nonatomic)NSInteger shopId;
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy) NSString * subtitle;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@end
我已经在 .m 类中合成了属性变量。
我尝试在我的主控制器中调用自定义类:
for(Shop *shops in feed.shops){
NSLog(@"reached");
AnnotationForId *shop = [[AnnotationForId alloc] init];
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(shops.latitude, shops.longitude);
shop.coordinate = coords;
//[[CLLocationCoordinate2DMake(shops.latitude, shops.longtitude)]];
shop.title = shops.name;
shop.subtitle = @"Coffee Shop";
[map addAnnotation:shop];
}
对为什么这不起作用的任何帮助都会很棒。谢谢。