0

数据设置


项目

-项目名称
-perHour

关系

-relatedTime(对许多)


时代

-dateAdded
-totalTime

关系
-relatedProject (to ONE)


这是我当前的核心数据设置。我会解释我想要做什么。我想让“项目”存储在表格视图控制器中,当您单击特定表格单元格时,它会将您带到另一个表格视图控制器,其中显示所有“时间”。

目前这是我的 Fetch 代码。

- (NSFetchedResultsController *)fetchedResultsController
{
    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Times" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"totalTime" ascending:NO];
    NSArray *sortDescriptors = @[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:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"relatedProject == %@", self.detailItem];
    [fetchRequest setPredicate:predicate];


    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&error]) {
        // Replace this implementation with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return _fetchedResultsController;
}

并且表格的格式与 masterViewController 上的格式相同,因此没有理由它不应该工作。但是,每当我单击“项目”的表格单元格时,它就会因以下错误而崩溃:

2013-09-20 17:41:57.595 test3[2642:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Projects''
*** First throw call stack:
(0x2d605f53 0x379dc6af 0x2d35b32b 0x78bd5 0x785df 0x2fe4a2f5 0x2fe4a23d 0x2fe49fd9 0x2feae871 0x2febc647 0x2fd9139b 0x2ff07e17 0x2fe25a83 0x2fe2588d 0x2fe25825 0x2fd77023 0x2fa0024b 0x2f9fba5b 0x2f9fb8ed 0x2f9fb2ff 0x2f9fb10f 0x2f9f4e3d 0x2d5d11d5 0x2d5ceb79 0x2d5ceebb 0x2d539ce7 0x2d539acb 0x3225a283 0x2fddba41 0x799bd 0x37ee4ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
4

0 回答 0