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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:13:14+00:00 2026-06-12T16:13:14+00:00

I am new to core data and NSFetched resultcontroller. So far I managed to

  • 0

I am new to core data and NSFetched resultcontroller. So far I managed to fill up my tableView. But now I want to divided into sections. Here is how my code looks like.

- (void)getKeepers // attaches an NSFetchRequest to this UITableViewController
{

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Team"];
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"sortOrder" ascending:YES]];
    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.genkDatabase.managedObjectContext
                                                                          sectionNameKeyPath:nil
                                                                                   cacheName:nil];

}

Let me sketch the situation. I am making an app for a football club. In my tableview I want for every position (goalkeeper,defender,winger,attacker) a new section. My core database looks like this.

- TEAM
   -name
   -Position
   -img_url
   -birthDate
   -sortOrder

I added the attribute sortOrder to sort my players. But can anybody help me to divide it into sections?

Thanks in advance !!

WHAT I DO IN MY CELL_FOR_ROW_AT_INDEX
In my cellForRowAtIndex I am doing not the usual thing. I am working with a custom tableviewCell which contains 6 imageviews. But its possible that a row only contains 4 images. You can see what I am trying to do over here.

#define IMAGES_PER_ROW  6

   NSInteger frcRow = indexPath.row * IMAGES_PER_ROW; // row in fetched results controller

    for (int col = 1; col <= IMAGES_PER_ROW; col++) {
        NSIndexPath *path = [NSIndexPath indexPathForRow:frcRow inSection:0];
        Team *team = [self.fetchedResultsController objectAtIndexPath:path];
        NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:team.image]];
        UIImage *image;
        if (imgData == nil) {
            // default image
            image = [UIImage imageWithContentsOfFile:@"keeperNil.jpg"];
        } else {
            image = [UIImage imageWithData:imgData];
        }
        [cell setImage:image forPosition:col];
        frcRow ++;
    }
  • 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-12T16:13:16+00:00Added an answer on June 12, 2026 at 4:13 pm

    Use the sectionNameKeyPath value to be the field you want to use for the sections.

    Then you need these three functions…

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

    This should be enough.

    Your cellForRowAtIndexPath function should look something like this…

    ...
    UITableViewCell* cell = [UITableViewCell dequeueCellWithReuseIdnetifier:@"blah"];
    
    Team *team = [self.fetchedResultsController objectAtIndexPath:indexPath];
    
    cell.textLabel.text = team.name;
    cell.detailTextLabel.text = team.position.
    

    Or something like that.

    The error you are getting means you are trying to access an array that doesn’t contain enough entries.

    If that doesn’t work then post your cellForRowAtIndexPath function.

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

Sidebar

Related Questions

I'm new to Core Data and I can't find the answer into the docs
I'm still new to Core Data, so forgive the question. I'm building an app
I'm new to core data and try to get all children objects of various
I am fairly new to core data technology and i searched a lot on
I'm using the new iOS 5 core data concurrency options. I have two threads:
I need a tabbed application with core data persistence. when i create a new
As an answer to a question I asked yesterday ( New Core Data entity
I am new to Core Data, and am designing a schema. I would like
I am new to Core Data. I have noticed that collection types are not
I am new to Core Data and I was wondering if I could get

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.