所以我试图让 UITableView 按部分(thing.title)显示对象列表,但按日期降序列出它们。
该表分为多个部分,这些部分被正确标记(部分标题是不同的事物标题)。
但是每个部分的对象只对了一半。每个部分中的对象按降序列出,但某些部分包含应该在其他部分中的数据。
正在发生的事情的一个例子:
<Header> Big Title Name
<data><Big Title><id=1></data>
<data><Big Title><id=4></data>
**<data><Small Title><id=6></data>** <-- should not be in this section
<Header> Small Title Name
<data><Small Title><id=11></data>
<data><Big Title><id=23></data> <-- should not be in this section
**<data><Small Title><id=66></data>**
这是我的代码的一部分:
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AReads" inManagedObjectContext:[NSManagedObjectContext defaultContext]];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
// Sort using the timeStamp property..
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Use the sectionIdentifier property to group into sections.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[NSManagedObjectContext defaultContext] sectionNameKeyPath:@"sessionTitle" cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
return fetchedResultsController;
}
- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
//return [(Sessions*)[masterSessions objectAtIndex: section] title];
id <NSFetchedResultsSectionInfo> theSection = [[fetchedResultsController sections] objectAtIndex:section];
NSString *theTitle = [theSection name];
return theTitle;
}