テーブルビューを並べ替えてセクション化するために、次の行があります。
NSSortDescriptor *sortDescriptorState = [[NSSortDescriptor alloc] initWithKey:@"positionSort" ascending:YES];
上記は、セルをそれぞれのpositionSort値でソートする整数値です。セクション名を表示するための以下のコードもあります。ただし、セクションは、positionSortの順序ではなく、アルファベット順に表示されます。どうすればこれを修正できますか?
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"position" cacheName:@"Master"];
ありがとう!
更新:@MartinRのおかげで、私は答えにたどり着くことができました。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
// Here I build up one of my Position objects using my unique position passed.
// I had to cast the object as NSMutableString* to get rid of a warning
Position * aPosition = [Position positionWithUniquePosition:(NSMutableString *)[[[sectionInfo objects] objectAtIndex: 0] position]
inManagedObjectContext:self.managedObjectContext];
// Once the above is done then I simply just accessed the attribute from my object
return aPosition.positionDescription;
}