【问题标题】:NSFetchedResultsController cache makes the table upside downNSFetchedResultsController 缓存使表格倒置
【发布时间】:2012-03-01 13:42:12
【问题描述】:
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.photoDatabase.managedObjectContext sectionNameKeyPath:@"status" cacheName:nil];

如果我将此缓存设置为 @"fetch_cache" 之类的东西,那么我的桌子就会倒置。第 1 节高于第 0 节!

我是 CoreData 的新手。我应该知道什么?

更新:我有一个排序描述符,它可以工作。忘记放在这里了。

【问题讨论】:

    标签: iphone ios core-data


    【解决方案1】:

    Core Data 中没有隐式排序,因此您可能需要告诉控制器您希望这些对象如何排序。

    查看NSSortDescriptor 并在您的NSFetchRequest 上致电-setSortDescriptors:

    【讨论】:

      【解决方案2】:

      sectionNameKeyPath 仅指定分组,它不会为您对这些对象进行排序。您必须将NSSortDescriptor 添加到您的request

      【讨论】:

      • 哦,对不起。我没有发布它,但我为请求定义了一个工作排序描述符。并且在缓存为零时请求工作正常。但是当我添加一个缓存文件时,它突然颠倒了。
      • Apple docs 开始,确保NSSortDescriptor 数组中的第一项按@"status" 正确排序对象。同样来自同一页面:If you are using a cache, you must call deleteCacheWithName: before changing any of the fetch request, its predicate, or its sort descriptors. You must not reuse the same fetched results controller for multiple queries unless you set the cacheName to nil.
      猜你喜欢
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 2023-03-05
      • 2014-04-30
      • 1970-01-01
      相关资源
      最近更新 更多