ios - Swift NSFetchedResultsController 不基于 sectionNameKeyPath 进行分段
问题描述
lazy var fetchedResultsController: NSFetchedResultsController<StoryTemplatePack> =
{
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
var frc: NSFetchedResultsController<StoryTemplatePack> = NSFetchedResultsController(fetchRequest: self.createFetchRequest(), managedObjectContext: managedObjectContext, sectionNameKeyPath: "sectionnum", cacheName: nil)
frc.delegate = self
return frc
}()
// FetchedResultsController: Create Request
func createFetchRequest() -> NSFetchRequest<StoryTemplatePack> {
let fetchRequest = NSFetchRequest<StoryTemplatePack>(entityName: "StoryTemplatePack")
fetchRequest.predicate = NSPredicate.init(format: "productidentifier != nil")
fetchRequest.sortDescriptors = [
NSSortDescriptor(key: "isfeatured", ascending: false),
NSSortDescriptor(key: "ispurchased", ascending: true),
NSSortDescriptor(key: "name", ascending: true)
]
return fetchRequest
}
应根据sectionnum
StoryTemplatePack 上的属性(这是在代码中计算的瞬态属性)对结果进行分段。
当我遍历 NSFetchedResultsController 的结果时,它会显示正确的部分编号和故事包名称。应该有 3 个部分,但 FRC 只报告 1 个部分。转储的结果还表明我正确地对结果进行了排序,以便部分值单调增加。
---- dumping frc, num sections: 1
section 0 pack Incredible Journeys
section 0 pack Out for a Date
section 0 pack Party Time
section 1 pack Holiday Craziness
section 1 pack In the Office
section 1 pack On the Internets
section 1 pack On the Job
section 1 pack School Daze
section 1 pack Social Networking
section 1 pack TV Troubles
section 1 pack Technology Takes Over
section 2 pack Christmas Shenanigans
---- done dumping
self.fetchedResultsController.sections!.count
当它应该返回 3 时返回 1。
我做错了什么或错过了什么?
解决方案
推荐阅读
- javascript - 有没有办法不从 v-for 内的按钮中移除焦点?
- amazon-web-services - AWS OpenVPN 实例无法通过 ssh 连接到其他连接到 Web 的 ec2 实例
- sql-server - 两个“相同”的数据库:一个报告“外键可能导致循环或多个级联路径”,而应用程序启动一个没有
- reactjs - 在 Microsoft Graph Toolkit 中使用不同的配置文件图像大小
- c# - 防止`IndexOf`匹配全角“?”寻找半角“?” 当 LC_ALL 为“ja.UTF-8”时
- xamarin - 如何在 C# 中为 Xamarin 网格元素指定行跨度?
- r - 将来自不同数据框的条形图并排
- python - 尝试计算语义分割任务的平均 IoU
- javascript - 如何在表单中触发没有按钮标签的ngSubmit?
- javascript - 实现对象的默认字符串描述的跨浏览器方式