sectionNameKeyPath与NSFetchedResultsController不工作 [英] sectionNameKeyPath with NSFetchedResultsController not working

查看:103
本文介绍了sectionNameKeyPath与NSFetchedResultsController不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体订单,属性已付,这是一个布尔值。

I have an entity Order with property paid, which is a boolean.

我想在 UITableView 中显示所有订单,但我想将它们分成两部分:'非付费'和'付费'。所以我想我只是给付费作为 sectionNameKeyPath ,像这样:

I want to display all orders in a UITableView, but I want to group them in two sections: 'Not Paid' and 'Paid'. So I thought I'd just give "paid" as sectionNameKeyPath, like this:

fetchedResultsController = [[NSFetchedResultsController alloc]
         initWithFetchRequest:fetchRequest
         managedObjectContext:managedObjectContext
           sectionNameKeyPath:@"paid"
                    cacheName:nil];

根据我的推理,这将导致两个部分,其中第一部分包含所有= NO(0),第二部分是付费= YES(1)。

According to my reasoning, this would result in two sections, where the first section contains all orders with paid = NO (0) and the second section with paid = YES (1).

但是当我添加一个新的付费= YES的订单时,部分。当我检入获取的结果控制器委托,我可以看到一个新的记录indexPath [0,0]创建!为什么不在第二部分插入?

But when I add a new Order with paid = YES, it shows up in the first section. When I check in the fetched results controller delegate, I can see that a new record with indexPath [0,0] is created! Why doesn't it get inserted in the second section?

推荐答案

尝试向使用的NSFetchRequest添加排序描述符数组与您的NSFetchedResultsController。

try adding an array of sort descriptors to the NSFetchRequest that is used with your NSFetchedResultsController.

您将首先按照付费布林排序,然后按任何其他您想排序。

You will want to sort on the paid boolean first, then whatever else you want to sort by.

这篇关于sectionNameKeyPath与NSFetchedResultsController不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆