我有以下錯誤:另一個,原因是:「+ entityForName:未能找到NSManagedObjectModel爲實體名稱
2012-04-18 10:15:49.585 FoodXJournal[13931:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'CommodityTypes''
我讀過的大多數與此主題的其他問題,和done一些檢查。
我有一個包含靜態表視圖的詳細視圖控制器。表視圖的一個單元格標記爲「刪除」,並鏈接到名爲「deleteCT」的segue。我希望應用程序刪除self.detailItem
,並在點擊此單元格時繼續到主視圖控制器。這是我的方法。所有NSLog線都用於調試。
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"deleteCT"]) {
if (![self.detailItem.myCommodities count]) {
NSLog(@"Testing");
NSLog(@"myCommodities is empty:%@", [self.detailItem.myCommodities count]);
NSLog(@"self.detailItem HAS a context:%@", [self.detailItem managedObjectContext]);
NSLog(@"self.detailItem is of CommodityTypes:%@", [[self.detailItem entity] name]);
NSLog(@"self.detailItem has a managed object model:%@", [[self.detailItem entity] managedObjectModel]);
[[self.detailItem managedObjectContext] deleteObject:self.detailItem];
}
}
}
這是日誌。我得到的這個方法,
2012-04-18 10:15:49.544 FoodXJournal[13931:fb03] Testing
我滿足我的條件刪除,
2012-04-18 10:15:49.544 FoodXJournal[13931:fb03] myCommodities is empty:(null)
錯誤消息說'+entityForName: could not locate an NSManagedObjectModel for entity name 'CommodityTypes'
,但self.detailItem
有一個背景。
2012-04-18 10:15:49.545 FoodXJournal[13931:fb03] self.detailItem HAS a context:<NSManagedObjectContext: 0x6d7e740>
是,self.detailItem
是我想的實體類型:
2012-04-18 10:15:49.546 FoodXJournal[13931:fb03] self.detailItem is of CommodityTypes:CommodityTypes
而且,沒錯,就是實體類型(NSLog(@"self.detailItem is of CommodityTypes:%@", [[self.detailItem entity] name]);
)的管理對象模型:
管理對象模型描述很長,所以我只在這裏展示它的第一部分:
2012-04-18 10:15:49.565 FoodXJournal[13931:fb03] self.detailItem has a managed object model:(<NSManagedObjectModel: 0x6d73250>) isEditable 0, entities {
Accounts = "(<NSEntityDescription: 0x6d71120>) name Accounts, managedObjectClassName Accounts, renamingIdentifier Accounts, isAbstract 0, superentity name Grandparent, properties {\n \"account_1\" = \"(<NSAttributeDescription: 0x6d6e9d0>), name account_1, isOptional 1, isTransient 0, entity Accounts,
向下滾動:
CommodityTypes = "(<NSEntityDescription: 0x6d71240>) name CommodityTypes, managedObjectClassName CommodityTypes, renamingIdentifier CommodityTypes, isAbstract 0, superentity name Grandparent, properties {\n myCommodities = \"(<NSRelationshipDescription: 0x6d701f0>), name myCommodities, isOptional 1, isTransient 0, entity CommodityTypes,
CommodityTypes
在管理對象模型中定義。
那麼爲什麼[[self.detailItem managedObjectContext] deleteObject:self.detailItem];
崩潰?!?
是否有某些原因我無法在prepareForSegue中刪除self.detailItem
?我是否需要爲單元格或標籤分配一個操作,然後以編程方式調用segue?
我嘗試用這三行代替問題行,以防存在一些訪問器問題,但它仍然崩潰。 '// [[self.detailItem managedObjectContext] deleteObject:self.detailItem]; NSManagedObjectContext * thisContext = [self。detailItem managedObjectContext]; NSManagedObject * thisItem = self.detailItem; [thisContext deleteObject:thisItem]; ' – adamek 2012-04-18 14:54:04
你確定它是導致崩潰的那條線嗎?錯誤消息看起來像來自_creates_託管對象 – jrturton 2012-04-18 14:54:05