Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:20:49+00:00 2026-05-24T18:20:49+00:00

When using the NSFetchedResultsController to create section headers for the UITableViewController the fetchedResultsController.sections has

  • 0

When using the NSFetchedResultsController to create section headers for the UITableViewController the fetchedResultsController.sections has an object for each item not each section.

//Set up the request
NSManagedObjectContext *context = self.managedObjectContext;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

[fetchRequest setEntity:[NSEntityDescription entityForName:@"Person" 
                                    inManagedObjectContext:context]];

[fetchRequest setFetchBatchSize:20];

NSSortDescriptor *sortDescriptor = nil;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" 
                                             ascending:YES];
NSArray *sortDescriptors = nil;
sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[sortDescriptor release]; sortDescriptor = nil;

[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptors release]; sortDescriptors = nil;

//setup fetch results controller
NSFetchedResultsController *controller = nil;
controller = [[NSFetchedResultsController alloc] 
              initWithFetchRequest:fetchRequest 
              managedObjectContext:context 
                sectionNameKeyPath:@"firstName" 
                         cacheName:@"PersonCache"];

__fetchedResultsController = controller;

[fetchRequest release]; fetchRequest = nil;

//IMPORTANT: Delete cache before changing predicate
[NSFetchedResultsController deleteCacheWithName:nil]; 
NSError *error = nil;
if (![controller performFetch:&error])
{
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
} else if ([[controller fetchedObjects] count] == 0){
    [self retrievePeoples];
}

NSLog(@"result count: %i", [[controller fetchedObjects] count]);
NSLog(@"section count: %i", [[controller sections] count]);
NSLog(@"sectionIndexTitles count: %i", [[controller sectionIndexTitles] count]);

This returns:

result count: 18
section count: 18
sectionIndexTitles count: 13

Shouldn’t the section count and the sectionIndexTitles count match? When the numberOfSectionsInTableView: and tableView:numberOfRowsInSection: methods are called I should just be able to look to the fetchedResultsController.section for a count without any additional sorting.

How do I setup the NSFetchResultsController properly to have each object in the sections array be for per section and not for all objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:20:50+00:00Added an answer on May 24, 2026 at 6:20 pm

    This was answered by Phillip Mills on another forum. The problem was I was using the entire firstName to create sections (not just the first letter). The fix is to update the entity to create the a section title whenever updated or changed. Apple’s DateSectionTitles has a sample of what to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am populating a UITableViewController with an NSFetchedResultsController with results creating sections that populate
I am presenting table view contents using NSFetchedResultsController which has a predicate: [NSPredicate predicateWithFormat:@visible
Please help with this issue of using NSFetchedResultsController. I created an object of NSFetchedResultsController
I am using an NSFetchedResultsController to manage displaying fetched managed objects in a table
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using JDeveloper , I started developing a set of web pages for a project
Using C#, I need a class called User that has a username, password, active
I'm using NSFetchedResultsController for my table view. I call -performFetch inside my controller's -viewDidLoad
I have a memory leak while using NSFetchedResultsController objectAtIndex: The stack frame is as
Afetr inserting a new record into my CoreData store using an NSFetchedResultsController, when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.