我有以下行来排序和划分我的表格视图。
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;
}