I'm having a rather peculiar issue.

I am trying to display a number of data entries from CoreData in a TableView. Following Developing iOS7 Apps from iTunesU, I used an NSFetchedResultsController. Initialization as follows.

```
// Set up fetch results controller
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext:[SessionManager sharedSessionManager].context];
[fetchRequest setEntity:entity];

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

// Sort using the timeAtConnect property.
// Do not sort ascending to allow for the latest session to appear on top.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeAtConnect" ascending:NO];
[fetchRequest setSortDescriptors:@[sortDescriptor ]];

// Use the sectionIdentifier property to group into sections.
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[SessionManager sharedSessionManager].context sectionNameKeyPath:@"timeAtConnect" cacheName:@"Root"];
_fetchedResultsController.delegate = self;

```

There are currently 4 entries in my CoreData set. What happens is that one of them ends up as a section header to one of the others, see picture. (Note: Each `timeAtConnect` is unique for each entry, which would make no sense to have a section for each, but never mind)

What is going on here? I can supply more code if necessary, but I figured this were the most important.

Thanks for any input!

![TableView in iOS Simulator](https://i.stack.imgur.com/LSgyT.png)

---

**Edit**

I actually want to have one section per entry. What I'm actually looking for is to group each timestamp (`timeAtConnect`) to the corresponding date. I.e. 2015-01-30 12:00 and 2015-01-30 13:00 would both end up under the section 2015-01-30, presumably by using Categories, but I never got that working. I figured this would be a first step to identify the error.

I also just thought; when I initialize the NSFetchedResultsController and the corresponding NSSortDescriptor, I sort `timeAtConnect` *descending*. This I do not specify with `sectionNameKeyPath` at the initialization of the NSFetchedResultsController. I believe these two must create the same sorting. How would you specify descending order for the section? (I want the latest entries to show up at the top).

UITableViewDataSource

```
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger count = [[self.fetchedResultsController sections] count];
    NSLog(@"Sections: %lu", (long) count);
    return count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];

    NSInteger count = [sectionInfo numberOfObjects];
    NSLog(@"Rows in section: %lu", (long)count);
    return count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    /*
     Use a default table view cell to display the event's title.
     */
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Session *session = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY-MM-dd HH:mm";

    // Same key as was used for sectioning and sorting
    cell.textLabel.text = [formatter stringFromDate:session.timeAtConnect];

    NSLog(@"Accessed cell at index.");

    return cell;
}

-(NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    id <NSFetchedResultsSectionInfo> theSection = [[self.fetchedResultsController sections] objectAtIndex:section];

    NSLog(@"Accessed title for header in section %lu", (long unsigned)section);

    return theSection.name;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    self.selectedSession = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSLog(@"Selected session %@", self.selectedSession.timeAtConnect);

    [self performSegueWithIdentifier:@"moveToDetailedView" sender:self];
}

```

---

**Edit 2**

I just noticed that actually not all entries are added. Some of the entries disappears. From the debug logs I can see that NSFetchedResultsController returns the number of sections that are displayed, i.e. it is not something to do with the UITableView, but rather the NSFetchedResultsController.