属性「グループ」を持つエンティティがあります。エンティティのリストを「グループ」(0 または 1) で 2 つのセクションにグループ化したいためです。
@property (nonatomic, retain) NSNumber * group;
fetchedResultsController で、sectionNameKeyPath を「グループ」として指定します。
self.fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:request managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"group" cacheName:nil];
以下のメソッド内の各セクションの行数を返すにはどうすればよいですか? 以下のエラーが発生しています:
Terminating app due to uncaught exception 'NSRangeException', reason:
'-[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
コードは次のとおりです。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[self.fetchedResultsController sections] objectAtIndex:section]
numberOfObjects];
}
また、これを試してみましたが、同じエラーが発生しました:
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]
objectAtIndex:section];
return [sectionInfo numberOfObjects];
このメソッドも実装したことに注意してください。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}