I use NSFetchedResultsController to populate a UITableView with results from a Core Data store with a moderate size of ~ 1,500 objects. The result controller is pretty standard - some hot spots for potential errors do not match this setting.
- Managed object context created on the same (main) thread as on
- No cache used (since sorting often changes)
- SectionNameKeyPath is used to divide the results into sections
The results of my section, however, are very strange. For example, consider this method used to set headers for section heading headers:
- (NSString *)titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.resultsController sections] objectAtIndex:section];
return [sectionInfo name];
}
I stopped at the specified line using a breakpoint, and using GDB, considered the following:
(gdb) po [[self resultsController] sectionNameKeyPath]
reviewDateString
(gdb) print section
$11 = 1
(gdb) print (int) [sectionInfo numberOfObjects]
$12 = 4
(gdb) po [sectionInfo name]
Wednesday, September 8th 2010
(gdb) po [[[sectionInfo objects] objectAtIndex:0] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:1] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:2] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:3] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
The problem should be obvious - why does the name [sectionInfo name] not match the values of the NameKeyPath section for each managed object in this section? The objects in the section look correctly grouped, the section name is simply incorrectly set.
The results look even stranger if you look at this:
(gdb) po [[self resultsController] indexPathForObject:(id)[[sectionInfo objects] objectAtIndex:0]]
<NSIndexPath 0x6615660> 2 indexes [459, 4294966310]
Now, obviously, from the above returned NSIndexPath should be [1,0], and not this dummy value.
I am completely at a dead end. Does anyone have any ideas? I will watch this question if you need more information.
[Change 1]
NSFetchedResultsController , ( / ) UISegmentedControl. , sortDescriptors sectionNameKeyPath, .
[ 2]
resultsController - accessor NSFetchedResultsController, , @synthesize.
- @ "reviewDateString" ( NameKeyPath), "po [sectionInfo name]", ", 13 2011 ".