0

UPDATE Here is an easy way to replicate the problem, open any app with a tableview loaded from core data. then in the tab bar, set a different tab to open the same tableview. and you get *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'FooSpelledCorrectly''

I have a second table view in a tabcontroller app, and the app crashes when the tab is selected. I get SIGABRT i like frogs

I have replicated the (h|m) files of a tableview and added them to the project. In the app delegate I added SearchGroupViewController *searchListController2;, the original tableview uses SearchDestinationsViewController *searchListController;

I feel I must be missing something simple. Any ideas where else to look? Do I need to create a second controller? Both .m files implement fetchedResultsController

- (NSFetchedResultsController *)fetchedResultsController {

    // Set up the fetched results controller if needed.
    if (fetchedResultsController == nil) {
        // Create the fetch request for the entity.
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        // Edit the entity name as appropriate.
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"FooSpelledCorrectly" inManagedObjectContext:managedObjectContext];
        [fetchRequest setEntity:entity];

        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"state" ascending:YES];// was name

        NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,sortDescriptor2, nil];// was 2// sortDescriptor,

        [fetchRequest setSortDescriptors:sortDescriptors];

        // Edit the section name key path and cache name if appropriate.
        // nil for section name key path means "no sections".
        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"state" cacheName:nil];//@"state"
        aFetchedResultsController.delegate = self;
        self.fetchedResultsController = aFetchedResultsController;

        //letters = [aFetchedResultsController valueForKey:@"alphabetIndex"];

        [aFetchedResultsController release];
        [fetchRequest release];
        //[sortDescriptor release];
        [sortDescriptor1 release];
        [sortDescriptor2 release];
        [sortDescriptors release];
    }

Crash Log:

2011-12-07 13:11:46.367 CoveredBridges[5762:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Recipe''
*** Call stack at first throw:

Thanks for any help or pointers! Robert

roberthuttinger
  • 1,172
  • 1
  • 17
  • 31
  • First thing everyone looks for in a question that has term "crash" is crash log. Where is your crash log ? Without crash log its waste of our time reading your entire question and figuring out what went wrong. – 0x8badf00d Dec 07 '11 at 18:21
  • 1
    Maybe a dumb question... but do you have an entity defined with the name `Recipe` in your Core Data schema? If so, did you possibly misspell it? – Chris Wagner Dec 07 '11 at 18:51
  • yes, and it all works on the first (initial) tableview. it is on the second tab (tableview) that it dies. – roberthuttinger Dec 07 '11 at 19:02

1 Answers1

0

In short, the answer was to instantiate the data in each view and release it when done in viewDidLoad. It was being loaded and shared app wide from the delegate before. Perhaps I could have checked for existence? It works now and I wanted to share.

managedObjectContext = nil;
managedObjectContext = [(RecipesAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyAwesomeData" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"state" ascending:YES];

        NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,sortDescriptor2, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"state" cacheName:nil];
        aFetchedResultsController.delegate = self;
        self.fetchedResultsController = aFetchedResultsController;

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor1 release];
    [sortDescriptor2 release];
    [sortDescriptors release];
roberthuttinger
  • 1,172
  • 1
  • 17
  • 31