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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:50:30+00:00 2026-06-12T19:50:30+00:00

there’s an interesting discussion on Apple Development forum about computing table view sections manually

  • 0

there’s an interesting discussion on Apple Development forum about computing table view sections manually for large row set. For viewing it a developer account is required:

NSFetchedResultsController fetching all objects in the DB…

To reassume for those without a dev account, an Apple technician suggest to use an entity containing index title, with to-many relationship to entities you want to display in rows.

The typical example is a collection of song or artist, where the index section title is the first letter A,B,C…

So, entity with title A will have a to-many relationship with songs starting with letter A, and so on.

The mechanism is to use a fetched results controller to retrieve all the song, and at the same time, launch a fetch request for retrieving an NSArray of indexes.

NSFetchRequest *req = //fetch request for section entity
NSArray *sections = [MOC executeFetchRequest:req error:&error];

It is quite easy to get sections count and rows in sections:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    NSInteger abc = [self.sections count];
    return abc;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    CardSection *s = (CardSection*)[self.sections objectAtIndex:section];
    NSInteger rows = [s.cards count];
    return rows;
}

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    CardSection *s = [self.sections objectAtIndex:section];
    NSString *title = s.title;
    return title;
}

However, the problem starts in cell for row at index path:

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSManagedObject obj = [_fetchedResultsController objectAtIndexPath:indexPath];
    // build cell....    
    return cell;
}

Because obviously the index path is referred to computed sections and rows, and therefore fetched controller goes out of range.

Of course this could be solved by recalling the section entity and ask for a specific index object in NSSet relationship, but in this way the benefit of having a fetched controller are lost.

I wonder if someone has tried this approach, and how did he manage to solve the issue.

  • 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-12T19:50:31+00:00Added an answer on June 12, 2026 at 7:50 pm

    The only solution I found so far, is to post parse the sections array to find the amount of preceding object at a specific index.

            int latestCount=0;
            // BOX_INT is just a personal macro for converting something to NSNumber
            self.totalAtIndex=[NSMutableDictionary dictionaryWithCapacity:0];
            [self.totalAtIndex setObject:BOX_INT(0) forKey:BOX_INT(0)];
            for (int i=1;i<[self.sections count];i++) {
                CardSection *cardSection = [self.sections objectAtIndex:i-1];
                latestCount = latestCount + [cardSection.cards count];
                [self.totalAtIndex setObject:BOX_INT(latestCount) forKey:BOX_INT(i)];
            }
    

    For example supposing this is my sections where [a,b] are just NSIndexPath:

    [0,0][0,1] (2 objects)
    [1,0]      (1 object)
    [2,0][2,1] (2 object)
    

    if I am at index 2, the [self.totalAtIndex objectAtIndex:2] would contain the amount of object stored before at index 0 + index 1, therefore return 3.
    And the index [2,1] is converted into [0,5].

    And this is the correspondent cellForRow:atIndexPath:

    - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        // hack index path
        NSInteger section = indexPath.section;
        NSInteger row = indexPath.row;
    
        int howManyBefore = [[self.totalAtIndex objectForKey:BOX_INT(section)] intValue];
        NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:row+howManyBefore inSection:0];
    
        NSManagedObject *obj = [_fetchedResultsController objectAtIndexPath:newIndexPath];
    
        // build and return cell
    
    }
    

    If someone has a better solution…

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

Sidebar

Related Questions

There is a table view with three sections. The last section may contain many
There is a column that exists in 2 tables. In table 1, this column
There are nice SO question and answers about this issue, but these options didn't
There are two table s : one is the master and one the detail
There was a similar question posted asking in general about alternatives to Qt. Well,
There's a way to, when the user touches outside the view, the app detects
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There are a lot of questions about full-joining in mysql(5.1.36). Of course the solution
There are numerous Agile software development methods. Which ones have you used in practice
There is a statement in the foudations of Qt Development book that goes as

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.