Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same problem and I've another solution - use a transient property for the sectionNameKeyPath i.e. category.sectionName. It seems that if you use a core data property as a sectionNameKeyPath it will try and sort with that.</p> <p>So using your example above:</p> <pre><code>NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"category.displayOrder" ascending:YES]; NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, sortDescriptor2, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"category.sectionName" cacheName:nil]; </code></pre> <p>Category.h:</p> <pre><code>@interface Category : NSManagedObject @property (nonatomic, retain) NSString* name; @property (nonatomic, retain) NSNumber* displayOrder; -(NSString*) sectionName; @end </code></pre> <p>Category.m:</p> <pre><code>@implementation Category @dynamic name; @dynamic displayOrder; -(NSString*) sectionName{ return self.name; } @end </code></pre> <p>Then in your view controller:</p> <pre><code>- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ id&lt;NSFetchedResultsSectionInfo&gt; sectionInfo=[self.resultsController.sections objectAtIndex:section]; return sectionInfo.name; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload