I am currently having a problem when my UITableViewController / UITableView, which uses NSFetchedResultsController, displays about 86 elements when the fetchLimit for fetchRequest for FRC is 4. I know that 86 elements satisfy the selection itself, and I know the reason that they appear because didChangeObject: atIndexPath ... is called for each of 86, and I insert as the default implementation view.
My question is why fetchLimit does not limit the number of objects that NSFetchedResultsController is trying to "modify" (insert in this case)?
My example of using the application is that the first tab displays the typical feed elements that I receive (in the side thread) when the application starts. I store them in CoreData in a separate context, which eventually merges with the main thread context and initiates FRC callbacks for what has changed. My question relates specifically to the first case when there are no items.
Here is my fetchRequest:
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
fetchRequest.entity = [NSEntityDescription entityForName:ENTITY_CONTENT_ITEM inManagedObjectContext:managedObjectContext];
[fetchRequest setFetchLimit:4];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"featured == YES AND contentType == %d", contentType]];
NSSortDescriptor *sortDateDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"sortDate" ascending:NO] autorelease];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDateDescriptor]];
The content level above is just a way to tear out what should appear on this tab, and other tabs. The recommended boolean property on an element, which is more like an off switch for display purposes.
Here is my didChangeObject:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[tableView cellForRowAtIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
I know that it will be difficult to answer this question, but even an explanation of how the FRC decides how many times to call didChangeObject would be really helpful.