Sto riscontrando un problema Non so da dove provenga, relativo a CoreData. Nel mio database, ho un set di categorie (con nome e descrizione), che contengono elementi (usando una relazione uno-a-molti).NSFetchedResultsController ha 0 sezioni
Voglio dividere la mia vista tabella in sezioni dato un attributo della classe Category
, ma quando provo a farlo usando sectionNameKeyPath:
, il risultato NSFetchedResultsController
ha 0 sezioni. Se passo nullo a questo parametro, ha 1 sezione.
Il codice è il seguente:
- (NSFetchedResultsController*) fetchedResultsController
{
if(fetchedResultsController)
return fetchedResultsController;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:10];
// Edit the sort key as appropriate.
NSSortDescriptor *checkDescriptor = [[NSSortDescriptor alloc] initWithKey:@"checked"
ascending:YES];
NSSortDescriptor *indexDescriptor = [[NSSortDescriptor alloc] initWithKey:@"orderIndex"
ascending:YES];
NSArray *sortDescriptors = @[checkDescriptor, indexDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"checked"
cacheName:nil];
NSError *error = nil;
if (![fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
return nil;
} else {
fetchedResultsController.delegate = self;
return fetchedResultsController;
}
}
Continua a generare 0 sezioni ... – gskbyte
Hai @sinthesize il tuo FetchedResultsController? Ho avuto un problema simile e questo era il problema. – Giovanni