1

每当我使用 Core Data 时,我都可以让程序运行并做它应该做的事情。但是我在尝试保存数据时经常遇到问题,我收到如下错误:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“+entityForName:找不到实体名称“Feedings”的 NSManagedObjectModel

据我所知,没有任何理由。

-(IBAction)saveData:(id)sender
{

Feedings *newFeed = [NSEntityDescription insertNewObjectForEntityForName:@"Feedings" inManagedObjectContext:self.managedObjectContext];

newFeed.time01 = time01TxtFld.text;
newFeed.time02 = time02TxtFld.text;
newFeed.time03 = time03TxtFld.text;
newFeed.time04 = time04TxtFld.text;
newFeed.time05 = time05TxtFld.text;
newFeed.time06 = time06TxtFld.text;
newFeed.time07 = time07TxtFld.text;

newFeed.feed01 = mls01TxtFld.text;
newFeed.feed02 = mls02TxtFld.text;
newFeed.feed03 = mls03TxtFld.text;
newFeed.feed04 = mls04TxtFld.text;
newFeed.feed05 = mls05TxtFld.text;
newFeed.feed06 = mls06TxtFld.text;
newFeed.feed07 = mls07TxtFld.text;


[self.managedObjectContext save:nil];  // write to database

[self.delegate theSaveButtonOnTheAddAppVCWasTapped:self];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Feedings" message:@"A new feeding record has been added." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
 }

这是我用于向数据库添加信息的代码,Xcode 没有错误 - 为什么让应用程序正常工作如此困难?

断点图片 断点图片


我将此行添加到 ViewDidLoad 方法:

NSLog(@"Entities : %@",[[self.managedObjectContext.persistentStoreCoordinator.managedObjectModel entities] valueForKey:@"time01"]);

哪个返回:

2012-08-25 13:33:43.572 喂养[735:fb03] 实体:(空)

这是崩溃的正确原因

4

0 回答 0