因此,我试图让一个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;
}