<small id='jRtnB'></small><noframes id='jRtnB'>

    1. <i id='jRtnB'><tr id='jRtnB'><dt id='jRtnB'><q id='jRtnB'><span id='jRtnB'><b id='jRtnB'><form id='jRtnB'><ins id='jRtnB'></ins><ul id='jRtnB'></ul><sub id='jRtnB'></sub></form><legend id='jRtnB'></legend><bdo id='jRtnB'><pre id='jRtnB'><center id='jRtnB'></center></pre></bdo></b><th id='jRtnB'></th></span></q></dt></tr></i><div id='jRtnB'><tfoot id='jRtnB'></tfoot><dl id='jRtnB'><fieldset id='jRtnB'></fieldset></dl></div>
        <bdo id='jRtnB'></bdo><ul id='jRtnB'></ul>

        <tfoot id='jRtnB'></tfoot><legend id='jRtnB'><style id='jRtnB'><dir id='jRtnB'><q id='jRtnB'></q></dir></style></legend>

      1. NSFetchedResultsController 忽略 fetchLimit?

        NSFetchedResultsController ignores fetchLimit?(NSFetchedResultsController 忽略 fetchLimit?)
          <tbody id='dgWED'></tbody>

        <small id='dgWED'></small><noframes id='dgWED'>

        • <legend id='dgWED'><style id='dgWED'><dir id='dgWED'><q id='dgWED'></q></dir></style></legend>
          <i id='dgWED'><tr id='dgWED'><dt id='dgWED'><q id='dgWED'><span id='dgWED'><b id='dgWED'><form id='dgWED'><ins id='dgWED'></ins><ul id='dgWED'></ul><sub id='dgWED'></sub></form><legend id='dgWED'></legend><bdo id='dgWED'><pre id='dgWED'><center id='dgWED'></center></pre></bdo></b><th id='dgWED'></th></span></q></dt></tr></i><div id='dgWED'><tfoot id='dgWED'></tfoot><dl id='dgWED'><fieldset id='dgWED'></fieldset></dl></div>

          1. <tfoot id='dgWED'></tfoot>
              <bdo id='dgWED'></bdo><ul id='dgWED'></ul>

                • 本文介绍了NSFetchedResultsController 忽略 fetchLimit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 NSFetchedResultsController 来使用 Core Data 的内容更新 UITableView.这是相当标准的东西,我相信你们都见过很多次,但是我遇到了一些小问题.首先是我的代码:

                  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 running into slight problem. First here's my code:

                  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
                  
                   NSEntityDescription *entity = [NSEntityDescription entityForName:@"Article" inManagedObjectContext:self.managedObjectContext];
                  
                   [fetchRequest setEntity:entity];
                  
                   [fetchRequest setFetchLimit:20];
                  
                   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(folder.hidden == NO)"];
                   [fetchRequest setPredicate:predicate];
                  
                   NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"sortDate" ascending:NO];
                   [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort1, nil]];
                  
                   NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]
                           initWithFetchRequest:fetchRequest
                           managedObjectContext:self.managedObjectContext
                           sectionNameKeyPath:nil
                           cacheName:nil];
                   [fetchRequest release];
                  
                   controller.delegate = self;
                  
                   self.fetchedResultsController = controller;
                  
                   [controller release];
                  
                   NSError *error = nil;
                   [self.fetchedResultsController performFetch:&error];
                   if (error) {
                    // TODO send error notification
                    NSLog(@"%@", [error localizedDescription]);
                   }
                  

                  问题在于,商店最初没有实体,因为它从网络服务下载和同步.发生的情况是 NSFetchedResultsController 用来自商店的 150 多行实体填充表,这就是 web 服务返回的数量.但是我设置了 20 的获取限制,这似乎被忽略了.但是,如果我关闭应用程序并使用商店中已有的数据重新开始,它就可以正常工作.我是我的代表,我这样做:

                  The problem is that initially the store has no entities as it downloads and syncs from a webservice. What happens is that the NSFetchedResultsController fills the table with over 150 rows of entities from the store, which is how many the webservice returns. But I am setting a fetch limit of 20 which it appears to be ignoring. However, if I close out the app and start again with data already in the store, it works fine. Im my delegate i do this:

                  #pragma mark -
                  #pragma mark NSFetchedResultsControllerDelegate methods
                  
                  - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
                   [self.tableView beginUpdates];
                  }
                  
                  
                  - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id  <NSFetchedResultsSectionInfo>)sectionInfo
                   atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
                  
                  switch(type) {
                      case NSFetchedResultsChangeInsert:
                          [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
                          break;
                  
                      case NSFetchedResultsChangeDelete:
                          [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
                          break;
                      }
                  }
                  
                  
                  - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
                  atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
                  
                  UITableView *tableView = self.tableView;
                  
                  switch(type) {
                  
                      case NSFetchedResultsChangeInsert:
                          [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
                          break;
                  
                      case NSFetchedResultsChangeDelete:
                          [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                          break;
                  
                      case NSFetchedResultsChangeUpdate:
                          [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
                          break;
                  
                      case NSFetchedResultsChangeMove:
                          [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                          [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
                          break;
                      }
                  }
                  
                  
                  - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
                   [self.tableView endUpdates]; 
                  }
                  

                  这几乎是来自 Apple 开发文档的复制粘贴,有什么想法吗?

                  Which is pretty much copy-paste from Apple's dev documents, any ideas what's goin on?

                  推荐答案

                  我知道这是一个老问题,但我有一个解决方案:

                  I know this is an old question, but I have a solution for it:

                  由于 NSFetchedResultsController 中存在一个不符合 NSFetchRequestfetchlimit 的已知错误,因此您必须手动处理限制UITableViewDataSourceNSFetchedResultsControllerDelegate 方法中的记录数.

                  Since there is a known bug in NSFetchedResultsController that doesn't honor the fetchlimit of the NSFetchRequest, you have to manually handle the limiting of records within your UITableViewDataSource and NSFetchedResultsControllerDelegate methods.

                  tableView:numberOfRowsInSection:

                  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
                  
                      id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
                  
                      NSInteger numRows = [sectionInfo numberOfObjects];
                  
                      if (numRows > self.fetchedResultsController.fetchRequest.fetchLimit) {
                  
                          numRows = self.fetchedResultsController.fetchRequest.fetchLimit;
                      }
                  
                      return numRows;
                  }
                  

                  控制器:didChangeObject:atIndexPath:forChangeType:newIndexPath:

                  - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
                  
                      switch(type) {
                  
                          case NSFetchedResultsChangeInsert:
                  
                              if ([self.tableView numberOfRowsInSection:0] == self.fetchedResultsController.fetchRequest.fetchLimit) {
                                  //Determining which row to delete depends on your sort descriptors
                                  [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.fetchedResultsController.fetchRequest.fetchLimit - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                  
                              }
                  
                              [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                                              withRowAnimation:UITableViewRowAnimationFade];
                          break;
                          ...
                      }
                  }
                  

                  这篇关于NSFetchedResultsController 忽略 fetchLimit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                • <legend id='39aze'><style id='39aze'><dir id='39aze'><q id='39aze'></q></dir></style></legend><tfoot id='39aze'></tfoot>
                  1. <small id='39aze'></small><noframes id='39aze'>

                        <tbody id='39aze'></tbody>
                        <bdo id='39aze'></bdo><ul id='39aze'></ul>

                          <i id='39aze'><tr id='39aze'><dt id='39aze'><q id='39aze'><span id='39aze'><b id='39aze'><form id='39aze'><ins id='39aze'></ins><ul id='39aze'></ul><sub id='39aze'></sub></form><legend id='39aze'></legend><bdo id='39aze'><pre id='39aze'><center id='39aze'></center></pre></bdo></b><th id='39aze'></th></span></q></dt></tr></i><div id='39aze'><tfoot id='39aze'></tfoot><dl id='39aze'><fieldset id='39aze'></fieldset></dl></div>