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

  • SEARCH
  • Home
  • 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 1043215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:37:56+00:00 2026-05-16T15:37:56+00:00

I have a UITableView that’s populated using core data & sqlite. I’d like to

  • 0

I have a UITableView that’s populated using core data & sqlite.

I’d like to have sections grouped in the UITableView based on an attribute from the database table.

e.g If i had a category field in the database table called “type”, what would be the best way of sectioning that data out?

I’ve seen examples using arrays, but I’m getting stuck with the core data. all the data is currently displayed from the database and I’d like to section it out somehow.

thanks in advance.

  • 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-16T15:37:57+00:00Added an answer on May 16, 2026 at 3:37 pm

    If you are using an NSFetchedResultsController to fetch your results and connect them to your UI it’s pretty easy. Just set the sectionNameKeyPath: parameter of the initWithFetchRequest call to NSFetchedResultsController.

    In this example, which is only slightly modified from the class reference for NSFetchedResultsController I have defined a key path that will use the section named “group” as the section title. Thus, if you have rows in your database that have a group set to “Cats” and other rows with a group set to “Dogs” your resulting table view will have 2 sections – one for cats and one for dogs.

    NSManagedObjectContext *context = <#Managed object context#>;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Configure the request's entity, and optionally its predicate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"<#Sort key#>" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];
    [sortDescriptors release];
    [sortDescriptor release];
    
    NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]
            initWithFetchRequest:fetchRequest
            managedObjectContext:context
            sectionNameKeyPath:@"groups"
            cacheName:@"<#Cache name#>"];
    [fetchRequest release];
    
    NSError *error;
    BOOL success = [controller performFetch:&error];
    

    For more information about key-paths you have to search for the key path documentation in the Xcode doc set. For simple cases though, it’s just the name of an attribute of your returned objects.

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

Sidebar

Related Questions

I have a UITableView that is being populated by core data. Now, when I
I have a UITableView that is populated with cells by core data and an
I have a UITableView that is grouped into sections and has a number of
I have a UITableView that fetches data from CoreData using FetchedResultsController and it registers
I have a UITableView that collects data from a database. What I would like
I have a uitableview that is populated from a sqlite query. I want to
I have a UITableview cell that gets a tally from a core data database.
I have a UITableView that displays some data that is read in at runtime
I have a UITableView that has five sections. Just as the title describes cellForRowAtIndexPath
I have a UITableView that I have set-up with 2 sections. The code below

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.