Terminating app due to uncaught exception 'NSInternalInconsistencyException'
I am working with cored开发者_高级运维ata..I have taken a navigation based app with coredata option checked..so in my first page will be a default tableview controller ,I addded an add button which opens another table view and i called it "anothertableviewcpntroller" the code which I wrote to on a add barbutton is below
- (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];
}
Then it opens the table view which,I have populated it with some dummy names ,and when I click on the first cell it opens one more view called detailviewcontroller
,
the code written on click of cells is below
- (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];
}
}
Here I have a text field where the user will add his name and click on save button,
The code for save button is below
- (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];
}
When he clicks on save button,the data should appear on the firstpage tableview controller,but its not happening I am getting the above error..i.e
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Recipes''
Can someone help me out.
Take a look at your data model in Xcode. You probably meant Recipe, not Recipes. The name you put in to insertNewObjectForEntityForName:
must be exactly the name in your model.
精彩评论