2013-06-17 2 views
0

Мой код отношение к проблеме:MapKit addAnnotation исключение: непризнанные селектор направлен например

Аннотация .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 

Мой импорт в мой MapView :

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

Добавление аннотации в контроллер просмотра. Это где ошибка происходит на [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' 

ответ

6

Ваш CityAnnotation класс должен обеспечить свойство/метод с именем coordinate. Подробности см. На странице MKAnnotation Protocol Reference.

Возможно, вы устраните неполадку, просто переименовав свое имущество coords в coordinate.

+0

Thats it! Спасибо! – Dan

Смежные вопросы