我成功地使用 NSFetchedResultsController 和 NSSortDescriptor 排序到一个表中,每个日期都有一个部分,以便今天的日期首先出现(降序日期顺序)。
但是,在该部分中,我希望按升序对时间进行排序。
这是我当前的代码,没有按时间排序:
//Set up the fetched results controller.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:kEntityHistory inManagedObjectContext:global.managedObjectContext];
fetchRequest.entity = entity;
// Sort using the timeStamp property..
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
fetchRequest.sortDescriptors = sortDescriptors;
//The following is from:
//http://stackoverflow.com/questions/7047943/efficient-way-to-update-table-section-headers-using-core-data-entities
NSString *sortPath = @"date.dayDate";
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:global.managedObjectContext sectionNameKeyPath:sortPath cacheName:nil];
fetchedResultsController.delegate = self;
请问如何更改代码以在此日期部分中按时间升序添加排序?