我正在使用coredata ..我已经选择了带有coredata选项的基于导航的应用程序。所以在我的第一页中将是一个默认的tableview控制器,我添加了一个添加按钮,打开另一个表视图,我称之为“ anothertableviewcpntroller” 我在添加栏按钮上写的代码在
下面- (void)insertNewObject {
DetailsTable *details = [[DetailsTable alloc] initWithNibName:@"DetailsTable" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: details];
[self.navigationController presentModalViewController:navController animated:YES];
[details release];
}
然后打开表视图,我用一些虚拟名称填充它,当我点击第一个单元格时,它再打开一个名为detailviewcontroller
的视图,
单击单元格时编写的代码位于
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
if(indexPath.row == 0)
{
AddRecipeViewController *addRecipeView = [[AddRecipeViewController alloc] initWithNibName:@"AddRecipeViewController" bundle:[NSBundle mainBundle]];
Recipes *recipes = (Recipes *)[NSEntityDescription insertNewObjectForEntityForName:@"Recipes" inManagedObjectContext:self.managedObjectContext];
addRecipeView.recipes = recipes;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: addRecipeView];
[self.navigationController presentModalViewController:navController animated:YES];
[addRecipeView release];
}
}
这里我有一个文本字段,用户将添加他的名字,然后点击保存按钮,
保存按钮的代码在
下面- (void)save {
recipes.recipeName = textFieldOne.text;
recipes.cookingTime = textFieldTwo.text;
NSLog(recipes.recipeName);
NSError *error = nil;
if (![recipes.managedObjectContext save:&error]) {
// Handle error
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
[self dismissModalViewControllerAnimated:YES];
}
当他点击保存按钮时,数据应出现在第一页tableview控制器上,但它没有发生我收到上述错误..i.e
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'+ entityForName:无法找到实体名称的'NSManagedObjectModel''食谱''
有人可以帮助我。
答案 0 :(得分:0)
在Xcode中查看您的数据模型。您可能需要食谱,而不是食谱。您输入insertNewObjectForEntityForName:
的名称必须完全您模型中的名称。