Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks to Rog I was able to wrap my head around this problem and come up with a solution. It's not as clean as I would want it so if anyone has a better approach I would love to hear about it.</p> <p>Based on what I have learned (I could be wrong, please let me know) you can only name sections (sectionNameKeyPath) by the property in which you are ordering your table. In my case, I wanted to sort my table using a property called displayOrder, but I didn't want my sections titles to be 0, 1, 2, etc. Instead I wanted the section titles to use the title property "Name1", "Name2", etc. that corresponds to the displayOrder. To do this I determine the header title based on the displayOrder in titleForHeaderInSection:</p> <pre><code> NSString *displayOrder = [sectionInfo name]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Platform" inManagedObjectContext:managedObjectContext]]; NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle:NSNumberFormatterNoStyle]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"displayOrder == %@", [numberFormatter numberFromString:displayOrder]]; [fetchRequest setPredicate:predicate]; Platform *platform; NSError *error = nil; NSArray *fetchResults = [managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; if ([fetchResults count] &gt; 0) { platform = [fetchResults objectAtIndex:0]; headerView.titleLabel.text = [platform name]; } else { headerView.titleLabel.text = @"Unknown"; } [numberFormatter release]; [fetchRequest release]; </code></pre> <p>Thanks Rog!</p>
 

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