NSFetchedResultsController ignores fetchLimit?

后端 未结 7 1993
春和景丽
春和景丽 2020-12-25 13:58

I have a NSFetchedResultsController to update a UITableView with content from Core Data. It\'s pretty standard stuff I\'m sure you\'ve all seen many times however I am runn

7条回答
  •  温柔的废话
    2020-12-25 14:46

    This is an old question but I just ran into it myself (in iOS 5). I think you're running into the bug described here: https://devforums.apple.com/message/279576#279576.

    That thread provides solutions based on whether you have a sectionNameKeyPath or not. Since I (like you) didn't, the answer is to decouple the tableview from the fetchedResultsController. For example, instead of using it to determine the number of rows:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
            return [[[self.fetchedResultsController sections] objectAtIndex:0] numberOfObjects];
    

    just return what you expect:

        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
            return fetchLimit;
    

    And in controller:didChangeObject, only insert the new object if the newIndexPath is within your fetchLimit.

提交回复
热议问题