2011-09-05 40 views
1

我收到以下錯誤CoreData與MapKit無法識別的選擇

2011-09-05 08:08:43.506 CaveConditions[7203:11903] -[NSManagedObject coordinate]: unrecognized selector sent to instance 0x7471910 
2011-09-05 08:08:43.507 CaveConditions[7203:11903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject coordinate]: unrecognized selector sent to instance 0x7471910' 

這就是我稱之爲

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
    request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context]; 
    request.predicate = [NSPredicate predicateWithFormat:@"(latitude > 0) AND (longitude > 0)"]; 

    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]]; 

它崩潰的addAnnotations線

在我Cave.h(它作爲MKAnnotation代表)

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 

In my Cave.m

- (CLLocationCoordinate2D)coordinate 
{ 
    CLLocationCoordinate2D location; 
    location.latitude = [self.latitude doubleValue]; 
    location.longitude = [self.longitude doubleValue]; 
    return location; 
} 

我是否錯過了什麼?

enter image description here

回答

4

錯誤提示,Cave類沒有註冊類在數據模型中的實體Cave。當你進行一次抓取時,你會得到一個通用的NSManagedObject,而不是Cave類的一個實例。

檢查數據模型是否有字段放入自定義NSManagedObject子類的名稱。它可能仍然被設置爲默認值。

+1

嗯,我不太明白你的意思是抱歉。我添加了模型部件的打印屏幕。我需要填寫什麼內容?它有什麼變化?因爲它在桌面視圖中運行良好。 – Chris

+4

標記爲'class'的字段。它目前具有NSManagedObject的默認值。您需要將其更改爲「洞穴」。 – TechZen

+0

這完美的作品。我需要使用我的所有Entinties嗎?它是爲了什麼? – Chris

相關問題