Skip to content

Instantly share code, notes, and snippets.

@g-1
Created April 8, 2014 11:26
Show Gist options
  • Save g-1/10111708 to your computer and use it in GitHub Desktop.
Save g-1/10111708 to your computer and use it in GitHub Desktop.
NSFetchedResultControllerでのセクションごとのソート順がUITableViewControllerで反映されない場合の対処法 ref: http://qiita.com/g-1/items/c97685fc98ff7e499c75
NSSortDescriptor* sortDescriptorWithName = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES];
NSArray* aSortDescriptor = @[sortDescriptorWithName];
[fetchRequest setSortDescriptors:aSortDescriptor];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"status >= 0"];
[fetchRequest setPredicate:predicate];
NSFetchedResultsController* fetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"status"
cacheName:@"Master"];
NSSortDescriptor* sortDescriptorWithName = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES];
NSSortDescriptor* sortDescriptorWithStatus = [[NSSortDescriptor alloc] initWithKey:@"status"
ascending:YES];
NSArray* aSortDescriptor = @[sortDescriptorWithStatus,sortDescriptorWithName];
[fetchRequest setSortDescriptors:aSortDescriptor];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"status >= 0"];
[fetchRequest setPredicate:predicate];
NSFetchedResultsController* fetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"status"
cacheName:@"Master"];
NSArray* aSortDescriptor = @[sortDescriptorWithName, sortDescriptorWithStatus];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment