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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:07:21+00:00 2026-06-15T04:07:21+00:00

I am writing a small app in which I uses coredata, I have data

  • 0

I am writing a small app in which I uses coredata, I have data like subjects which contains
Maths, Science, and other Books.

Other books can be added or deleted, but maths and science cannot be deleted,they will get added by default when new student is added. When I fetch my results, i should get all the book names including maths and science.

What I want do is display the data in three section with headers as Maths, Science, and Others. Maths and science will contain only one row, i.e, maths or science. And all other books should be in reading section.

How to proceed to achieve this?

  • 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-06-15T04:07:22+00:00Added an answer on June 15, 2026 at 4:07 am

    When you create your NSFetchResultsController use the entity name for the books table in the fetch request.

    Then use this…

    NSFetchedResultsController *aController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"typePropertyName" cacheName:nil];
    

    typePropertyName will be the path to get from a book to the name of the section it will be in.

    It could just be @”typeName” if you have it directly in the Book table or it could be @”type.name” if you have a relationship to a table called type and then that table has a field called name.

    Anyway, that will create a NSFetchedResultsController with the sections in…

    Full code will be something like …

    #pragma mark - fetched results controller
    
    - (NSFetchedResultsController*)fetchedResultsController
    {
        if (_fetchedResultsController != nil) {
            return _fetchedResultsController;
        }
    
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Book"];
        [request setFetchBatchSize:20];
    
        NSSortDescriptor *sdType = [[NSSortDescriptor alloc] initWithKey:@"type.name" ascending:YES];
        NSSortDescriptor *sdName = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
        [request setSortDescriptors:@[sdType, sdName]];
    
        NSFetchedResultsController *aController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"type.name" cacheName:nil];
    
        aController.delegate = self;
        self.fetchedResultsController = aController;
    
        NSError *error = nil;
        if (![self.fetchedResultsController performFetch:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
        return _fetchedResultsController;
    }
    

    Then in the tableViewController you can have this…

    - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
    
        return [sectionInfo name]
    }
    

    This will then use the section name as the header for each section.

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

Sidebar

Related Questions

I am writing small app, using Play Framework 2.0 which uses Ebean as ORM.
I am writing a small app that uses the GAE. I have parts of
I've been writing a small Facebook app which uses the unified_thread table using FQL.
I'm writing small VB.Net app which should build reports based on data gathered from
I am writing a small console app which have to overwrite a txt file
I am writing a small app in which android device tries to send a
I am writing a small app ( initApp.js , initApp.routinj.js , initApp.controller.js ) which
I have an application where I am reading and writing small blocks of data
I'm writing a small App in which i read some text from to console,
I'm writing small utility app (JBoss Netty based) which should perform some trivial login

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.