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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:55:29+00:00 2026-06-09T07:55:29+00:00

I have a UITableView populated with a standard NSFetchedResultsController. However I’d like to prepend

  • 0

I have a UITableView populated with a standard NSFetchedResultsController. However I’d like to prepend a row or a section (row preferably but either would works fine really.)

The only way I can possibly see doing this right now is to rewrite all the NSIndexPath’s manually when dealing with the section/rows dealing with the data from NSFetchedResultsController to trick it into seeing section at index 0 and starting with row at index 0. This however seems like a really bad idea that would quickly get confusing so I’d like to preferable avoid that.

A good example of this would be in the official Twitter app when you start it up for the first time and I walks you through adding some people from your friends list.

Screenshot of Twitter app's suggestions page, with the relevant sections highlighted

The red section is pretty much what I’d like to achieve, and the yellow section I assume is the results from an NSFetchedResultsController in the same section (though with their custom styling it might be a separate section.)

  • 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-09T07:55:30+00:00Added an answer on June 9, 2026 at 7:55 am

    This is possible to do in a fairly clean way.

    I’m assuming you’re starting with a standard tableview set up with a standard NSFetchResultsController that uses Apple’s sample code.

    First you need two utility functions:

    - (NSIndexPath *)mapIndexPathFromFetchResultsController:(NSIndexPath *)indexPath
    {
        if (indexPath.section == 0)
            indexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
    
        return indexPath;
    }
    
    - (NSIndexPath *)mapIndexPathToFetchResultsController:(NSIndexPath *)indexPath
    {
        if (indexPath.section == 0)
            indexPath = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section];
    
        return indexPath;
    }
    

    These should be fairly self explanatory – they’re just helpers to deal with adding the extra row when we want to use an index path from the fetched results controllers to access the table, or removing it when going the other way.

    Then we need to create the extra cell:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"MyCellId";
    
        if (indexPath.section == 0 && indexPath.row == 0)
        {
            UITableViewCell *cell;
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            cell.textLabel.text = NSLocalizedString(@"Extra cell text", nil);
    
            return cell;
        }
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        }
    
        [self configureCell:cell atIndexPath:indexPath];
    
        return cell;
    }
    

    make sure we configure it correctly (configurecell will only be called for cells from the fetch results controller):

    // the indexPath parameter here is the one for the table; ie. it's offset from the fetched result controller's indexes
    - (void)configureCell:(SyncListViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
        indexPath = [self mapIndexPathToFetchResultsController:indexPath];
    
        id *obj = [fetchedResultsController objectAtIndexPath:indexPath];
        <... perform normal cell setup ...>
    }
    

    and tell the tableview it exists:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        NSInteger numberOfRows = 0;
    
        if ([[fetchedResultsController sections] count] > 0) {
            id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
            numberOfRows = [sectionInfo numberOfObjects];
        }
    
        if (section == 0)
            numberOfRows++;
    
        return numberOfRows;
    }
    

    and respond to selection:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        if (indexPath.section == 0 && indexPath.row == 0)
        {
            [self doExtraAction];
            return;
        }
    
        ... deal with selection for other cells ...
    

    and then remap any updates we get from the results controller:

    - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
        UITableView *tableView = self.tableView;
    
        indexPath = [self mapIndexPathFromFetchResultsController:indexPath];
        newIndexPath = [self mapIndexPathFromFetchResultsController:newIndexPath];
    
        switch(type) {
            ... handle as normal ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UITableView populated by a NSFetchedResultsController . The initial fetch works fine.
I have a UITableView populated by a SQLite database. I added Section-based Grouping using
I have a UITableView that's populated using core data & sqlite. I'd like to
I have a UITableView populated by a feed from searchtwitter.com. I also have a
I have a UITableView populated with a location-based datasource. I'm calling [self updateView]; to
I have a UITableView that is being populated by core data. Now, when I
I have a working UITableView in my view controller. It is being successfully populated
I have UITableView.when i click on it's 1 st row one another UITableView opens
I have a UITableView populated (previously saved via a button in navbar), with transactions.
I have a UITableView that gets populated from CoreData via a controller that implements

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.