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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:59:17+00:00 2026-06-12T17:59:17+00:00

So I am trying to get a UITableView to show a list of objects

  • 0

So I am trying to get a UITableView to show a list of objects by section (thing.title), but list them in descending order by date.

The table is is split into sections, which are labeled correctly (section headers are the different thing titles).

But the objects in each section are only half correct. The objects in each section are listed in descending order, but some sections contain data that should be in other sections.

An example of what is happening:

<Header> Big Title Name
    <data><Big Title><id=1></data>
    <data><Big Title><id=4></data>
    **<data><Small Title><id=6></data>**   <-- should not be in this section


<Header> Small Title Name
    <data><Small Title><id=11></data>
    <data><Big Title><id=23></data>  <-- should not be in this section
    **<data><Small Title><id=66></data>**

Here is part of my code:

- (NSFetchedResultsController *)fetchedResultsController {

if (fetchedResultsController != nil) {
    return fetchedResultsController;
}

/*
 Set up the fetched results controller.
 */
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AReads" inManagedObjectContext:[NSManagedObjectContext defaultContext]];
[fetchRequest setEntity:entity];

// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];

// Sort using the timeStamp property..
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

// Use the sectionIdentifier property to group into sections.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[NSManagedObjectContext defaultContext] sectionNameKeyPath:@"sessionTitle" cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

return fetchedResultsController;
}


- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:  (NSInteger)section
{
//return [(Sessions*)[masterSessions objectAtIndex: section] title];
id <NSFetchedResultsSectionInfo> theSection = [[fetchedResultsController sections] objectAtIndex:section];



NSString *theTitle = [theSection name];


return theTitle;
}
  • 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-12T17:59:18+00:00Added an answer on June 12, 2026 at 5:59 pm

    The key used as sectionNameKeyPath of a fetched results controller and the key used in the first sort descriptor must either be the same keys or generate the same relative ordering. So you cannot use sessionTitle as sectionNameKeyPath and a completely different key timeStamp as sort descriptor for the sections.

    In your case, it is probably the best to use timeStamp as sectionNameKeyPath and in the sort descriptor. This will ensure that all entries are correctly grouped into sections.

    To display the sessionTitle instead of the timeStamp in the section header, you can modify titleForHeaderInSection:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
        id <NSFetchedResultsSectionInfo> sectionInfo = [[self.controller sections] objectAtIndex:section];
        return [[[sectionInfo objects] objectAtIndex:0] sessionTitle];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my UITableView to show cells with images placed on them
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I have a grouped UITableView in my code and am trying to get the
I'm trying to make a UITableView like the native calendar app: but I'm trying
Hello I am trying to get profile image of facebook user in Table's cell.image.
I have been searching for a while trying to get help, but without luck
I am trying to get the sections and index for UITableView from Sqlite (I
How to get the youtube videos in JSON formate for list in UITableView .
I am trying to get the UITableView cells to fit the text. So far

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.