0

UPDATE 這是一個簡單的方法來複制問題,打開任何應用程序與從核心數據加載的tableview。然後在標籤欄中,設置不同的選項卡以打開相同的tableview。你得到*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'FooSpelledCorrectly''TabController中的第二個表視圖 - 崩潰

我有一個tabcontroller應用程序中的第二個表視圖,並且該應用程序在選擇該選項卡時崩潰。我得到SIGABRT i like frogs

我已經複製了tableview的(h | m)文件並將它們添加到項目中。在應用程序代理中,我添加了SearchGroupViewController *searchListController2;,原始tableview使用SearchDestinationsViewController *searchListController;

我覺得我必須缺少一些簡單的東西。任何想法在哪裏看?我是否需要創建第二個控制器? 兩個.m文件執行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]; 
    } 

崩潰日誌:

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: 

感謝任何幫助或指針! Robert

+0

每個人在一個有「崩潰」一詞的問題中尋找的第一件事就是崩潰日誌。你的崩潰日誌在哪裏?沒有崩潰記錄它浪費我們的時間閱讀你的整個問題,並找出出了什麼問題。 – 0x8badf00d

+1

也許是一個愚蠢的問題......但是你的核心數據模式中是否有一個名爲'Recipe'的實體定義?如果是這樣,你可能拼錯了嗎? –

+0

是的,它都可以在第一個(初始)tableview上運行。它在第二個選項卡(tableview)上死了。 – roberthuttinger

回答

0

總之,答案是在每個視圖中實例化數據並在viewDidLoad中完成時釋放它。它之前被加載並與代表共享應用程序。也許我可以檢查存在?它現在有效,我想分享。

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];