Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should use your CoreData NSFetchedResultsController to get your sections/indexes.<br> You can specify the section key in the fetch request (I think it has to match the first sort key): </p> <pre><code>NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" // this key defines the sort ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"name" // this key defines the sections cacheName:@"Root"]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; </code></pre> <p>Then, you can get the section names like this:</p> <pre><code>- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { id &lt;NSFetchedResultsSectionInfo&gt; sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo name]; } </code></pre> <p>And the section indexes are here:</p> <pre><code>id &lt;NSFetchedResultsSectionInfo&gt; sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; [sectionInfo indexTitle]; // this is the index </code></pre> <p>Changes to the content just indicate that the table needs to be updated: </p> <pre><code>- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [self.tableView reloadData]; } </code></pre> <p><strong>UPDATE</strong><br> This only works for the index and fast index scrolling, not for the section headers.<br> See <a href="https://stackoverflow.com/questions/1741093/how-to-use-the-first-character-as-a-section-name/1741131#1741131">this answer</a> to "How to use the first character as a section name" for more information and details on how to implement first letters for section headers as well as the index.</p>
    singulars
    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. 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