I have an SQL based core data managed document, and I present its contents using a tableview backed by an NSFetchedResultsController. The data is indeed shown and it’s all there, but it is not sorted even though I really tried to make it sort. Here’s how I set the fetched results controller:
- (void)setupFetchedResultsController // attaches an NSFetchRequest to this UITableViewController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Notebook"];
NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:descriptor];
// no predicate because we want ALL the notebooks
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.dbContext
sectionNameKeyPath:nil
cacheName:nil];
}
name is an attribute of type string. I also tried with another attribute of type NSDate. None of them work – the data is not sorted even when the tableview is presented immediately when the app starts before any changes were applied to the document.
Ideas?
Ok, I guess this one goes into the X-files section of stack overflow. The problem was resolved, and I have no idea what I did to solve it, if at all. I was working on other parts of my app for the past few days, and at some points the results of the fetched results controller started being sorted again. Perhaps it was some bug in Xcode that resolved when I restarted it, or something that I change in another part of the app, I just don’t know. Thanks for the attempts at helping me though…