問題が発生しています。どこから来たのかわからない、CoreDataに関連しています。私のデータベースでは、(1対多の関係を使用して)要素を含む一連のカテゴリ(名前と説明付き)を持っています。NSFetchedResultsControllerには0のセクションがあります
Category
クラスの属性を与えられたセクションでテーブルビューを分割したいのですが、sectionNameKeyPath:
を使用しようとすると、NSFetchedResultsController
セクションは0セクションになります。このパラメータにnilを渡すと、1つのセクションがあります。
コードは次のとおりです。
- (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;
}
}
0個のセクションを生成し続けます... – gskbyte
fetchedResultsControllerを@synthesizeしましたか?私も同様の問題があり、これが問題でした。 – Giovanni