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 6095863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:51:37+00:00 2026-05-23T12:51:37+00:00

When sorting a table of objects from Core Data, I’d like to set a

  • 0

When sorting a table of objects from Core Data, I’d like to set a custom string for the section heading that includes an attribute. For example, I’d like the section name to display “4 Stars”, instead of just 4. I’ve fiddle with it, but It seems to get grumpy if I try to set the string for the sectionNameKeyPath to anything other than an Entity Attribute and only an entity attribute. Here’s what works for attribute only, and one of a few attempts to customize the string which breaks is commented out.

NSSortDescriptor *ratingDescriptor = [[NSSortDescriptor alloc] initWithKey:@"starRating" ascending:NO];
    sortDescriptors = [NSArray arrayWithObjects:ratingDescriptor, nameDescriptor, nil];
    [ratingDescriptor release], ratingDescriptor = nil;
    // NSString *starSectionHeading = [NSString stringWithFormat:@"%d Stars", @"starRating"];
    // sectionKeyPath = starSectionHeading;
sectionKeyPath = @"starRating";
  • 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-23T12:51:38+00:00Added an answer on May 23, 2026 at 12:51 pm

    Set your sectionNameKeyPath to the “starRating” but then modify the output in the table view. The FRC will sort things and tidy things up in sections you just have to change what you would normally display as the header string.

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
    {
        // Display the stars as section headings.
        int stars = [[[[fetchedResultsController sections] objectAtIndex:section] valueForKey:@"name"] intValue];
        if(stars == 1)
        {
            return @"1 Star"
        }
        else
        {
            return [NSString stringWithFormat:@"%u Stars", stars];
        }
    }
    

    I do this in some table views where the output format is handled in a generic fashion (I delegate the header titles to a another controller class given the first sort descriptor path and the value of the title). So you are not limited to hard coding the table view delegate methods like the above code.

    You also get a chance to localize the string here as well, I have to deal with 15 localizations in my app and you have to think about things a bit differently when localizing.

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

Sidebar

Related Questions

I've got a table which Im sorting with tablesorter ( http://tablesorter.com ). Within that
This question is similar to GWT Table that supports sorting, scrolling and filtering However
I am trying to create a pageing and sorting object data source that before
Right now I have an UITableViewController that displays a set of Artist objects sorted
I'm trying to convert an existing app to use core data. I've set up
I'm doing sorting based on a field that references another table (and sorting on
I've got an MVC application written with Zend Framework that pulls data from an
I want to use Christian Bach's tableSorter client-side table sorting jQuery plugin with my
I have a problem with sorting items in table in PHP. Here is what
I have a huge table and I want simple sorting. It could be so

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.