gpt4 book ai didi

iphone - Mapkit addAnnotation异常: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 18:22:44 24 4
gpt4 key购买 nike

我的与问题相关的代码:

注释.h文件

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface CityAnnotation : NSObject <MKAnnotation> {
NSString *name;
NSString *country;
CLLocationCoordinate2D coords;
}

@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *country;
@property (nonatomic,assign) CLLocationCoordinate2D coords;

-(id)initWithTitle:(NSString *)cityname AndCountry:(NSString *)countryname AndCoords: (CLLocationCoordinate2D)coordinate;


@end

注释.m文件

#import "CityAnnotation.h"

@implementation CityAnnotation

@synthesize name,country,coords;

-(id)initWithTitle:(NSString *)cityname AndCountry:(NSString *)countryname AndCoords:(CLLocationCoordinate2D)coordinate
{
self = [super init];
if (self){
self.name = cityname;
self.country = countryname;
self.coords = coordinate;
}
return self;

}

@end

我导入我的 map View :

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "tableViewController.h"
#import "City.h"
#import "CityAnnotation.h"

在 View Controller 中添加注解。这是在 [self.mapView addAnnotation:newAnnotation];

上发生错误的地方
- (void)viewDidLoad
{
[super viewDidLoad];
CityAnnotation *newAnnotation = [[CityAnnotation alloc]initWithTitle:self.SelectedCity.name AndCountry:self.SelectedCity.country AndCoords:self.SelectedCity.location];
[self.mapView addAnnotation:newAnnotation];


}

我收到这个错误:

-[CityAnnotation coordinate]: unrecognized selector sent to instance 0x85c7d70
2013-06-17 12:15:57.694 JsonTest[1769:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CityAnnotation coordinate]: unrecognized selector sent to instance 0x85c7d70'

最佳答案

您的 CityAnnotation 类必须提供名为 coordinate 的属性/方法。查看MKAnnotation Protocol Reference了解详情。

您只需将 coords 属性重命名为 coordinate 即可解决您的问题。

关于iphone - Mapkit addAnnotation异常: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17154440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com