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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:39:04+00:00 2026-05-13T19:39:04+00:00

I struggle with Core Data on the iPhone about the following: I have a

  • 0

I struggle with Core Data on the iPhone about the following:
I have a 1-to-many relationship in Core Data. Assume the entities are called recipe and category. A category can have many recipes.
I accomplished to get all recipes listed in a UITableView with section headers named after the category.
What i want to achieve is to list all categories as section header, even those which have no recipe:

category1   <--- this one should be displayed too
category2
     recipe_x
     recipe_y
category3
     recipe_z

 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:managedObjectContext];
 [fetchRequest setEntity:entity];
 [fetchRequest setFetchBatchSize:10];

 NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"category.categoryName" ascending:YES];
 NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"recipeName" ascending:YES];
 NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,sortDescriptor2, nil];

 [fetchRequest setSortDescriptors:sortDescriptors];
 NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"category.categoryName" cacheName:@"Recipes"];

What is the most elegant way to achieve this with core data?

  • 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-13T19:39:04+00:00Added an answer on May 13, 2026 at 7:39 pm

    Sections are not really meant to be shown if there are no rows in them. That is the way the UITableView is designed. If you really wanted to force it you would need to add logic to your datasource call of -numberOfRowsForSection: to make it appear that there is always one row and then you could play with the -heightForRowAtIndexPath: to try and hide the row.

    Having said that, it is a terrible idea. Let the sections hide themselves like they were designed to.

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

Sidebar

Related Questions

I have the following code written to make my lazy second CPU core working.
I struggle a little with the understanding of generics and how they can and
Hello I have the followong struggle in my head. I want a text-field in
I struggle with working with Internet Explorer. Issue one: I have used min-height:100% and
I always struggle with dealing with normalised data, and how I display it. Maybe
I have been having constant struggle with Visual Studio debugger and finally got fed
It's very simple task, but I struggle for hours. I have parse xml from
Everyday I struggle with algorithm questions and try to ask here which I can't
Hi friends am new to iphone developing. Am struggle with add badge values on
I struggle to have gems correctly loading in a Snow Leopard environment. I installed

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.