ObjectAtIndex: 0] numberOfObjects]> fetchLimit

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];

// Set a limit on the number of items returned
[fetchRequest setFetchLimit:4];

// Set a Predicate to limit the fetch to featured items only
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"featured == YES AND contentType == %d", contentType]];

// Set the sort descriptors
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];
       // Reloading the section inserts a new row and ensures that titles are updated appropriately.
       [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.

+3
1

https://devforums.apple.com/thread/60319?tstart=0

, , . , CoreData/NSFetchedResultsController/UITableViewController iOS4.0.

3.2 4.0, , . , , Name, . cacheName nil + deleteCacheWithName, . , , , . , ( , executeFetch). .description ( -description), , db -description.

4.0 UITableView, , UITableViewController. , -reloadData iOS , iOS4.

-BenT (Apple)

, .description NameKeyPath initWithFetchRequest . , -, , , , , , , .

4.0, 3.0 reloadData controllerDidChangeContent. , .

+1

Source: https://habr.com/ru/post/1755808/


All Articles