- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个获取请求,应该生成一个包含结果中的两个部分的 TableView 。
我的模型:
@interface Player : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * isFacebookFriend;
此模型上的获取请求应该导致一个部分中的人在一个部分中是 isFacebookFriend == YES,而在第二部分中是 isFacebookFriend == NO。
我试过
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
HBAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Player" inManagedObjectContext:appDelegate.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
[fetchRequest setSortDescriptors:@[nameDescriptor]];
[fetchRequest setResultType:NSDictionaryResultType];
[fetchRequest setPropertiesToGroupBy:@[@"isFacebookFriend"]];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:nil cacheName:@"playerCache"];
NSError *error;
[_fetchedResultsController performFetch:&error];
但这并没有做到。错误是:
2013-06-12 12:27:28.364 TwentyQuestions[25015:c07] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0xb676aa0>.
2013-06-12 12:27:31.119 TwentyQuestions[25015:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'SELECT clauses in queries with GROUP BY components can only contain properties named in the GROUP BY or aggregate functions ((<NSAttributeDescription: 0xc382320>), name hasRegisteredForGame, isOptional 1, isTransient 0, entity Player, renamingIdentifier hasRegisteredForGame, validation predicates (
), warnings (
), versionHashModifier (null)
userInfo {
}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null) is not in the GROUP BY)'
最佳答案
要创建带有部分的 TableView ,您必须使用 sectionNameKeyPath
参数NSFetchedResultsController
。您还必须添加一个(第一个)排序描述符来排序根据部分名称键路径。
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSSortDescriptor *isFacebookFriendDescriptor = [[NSSortDescriptor alloc] initWithKey:@"isFacebookFriend" ascending:NO];
[fetchRequest setSortDescriptors:@[isFacebookFriendDescriptor, nameDescriptor]];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:appDelegate.managedObjectContext
sectionNameKeyPath:@"isFacebookFriend"
cacheName:@"playerCache"];
您不必设置 setPropertiesToGroupBy
,我也不建议设置NSDictionaryResultType
因为它会禁用自动更新通知。
关于ios - 带分组的核心数据 NSFetchRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17073659/
我想使用 iOS10 中引入的新核心数据 API。 @available(iOS 10.0, *) open class func fetchRequest() -> NSFetchRequest 我
使用此函数对表格 View 中的单元格进行排序。我的获取请求中出现错误。 do 循环内的行 notes = try context.fetch(request) 导致错误,请求带有下划线 错误显示“无
我的核心数据模型中有一个名为 Task 的实体。 Task 实体有一个名为 date 的可转换属性。 date 属性的类是一个名为 TDate 的类(它符合 NSCoding,因此是一个可转换的属性)
使用 NSFetchedResultsController 和 NSFetchRequest 可以设置返回每个属性中最高值的查询。 例如: Entity_001 A=F B=27 C=57 Entit
我有两个实体:Patient 和 Job。患者与作业具有一对多关系,称为“作业”,而作业与患者具有一对一关系,称为“患者”。作业具有名为“dueDate”(日期)和“已完成”(BOOL)的属性,而患者
如果不提供 NSSortDescriptor,我们就无法使用 NSFetchRequest。我想要做的就是获取结果并按创建顺序显示它们。有没有内置的方法可以做到这一点?或者我必须创建一个新的“自动增量
我必须为我的 iPhone 应用程序创建一个 NSFetchRequest,它返回与以下 SQL 语句相同的结果: SELECT week , year , SUM(durat
我在 MacOsX 10.6 上使用 SQL 存储时遇到了 CoreData 的奇怪问题。我有一个NSManagedObject子类名为 Family具有属性 name和关系personList连接到
我的数据模型如下:类别 —>名字 —>items(“汽车”类型的项目数组) 我正在尝试获取部分作为名称,行应该是项目(这是一个 NSArray) 这是我的代码,我期望将行作为 Car 返回,但它仍然返
我有一个数据列表,其中父子层次结构最多为三个级别。例如 项目A(祖 parent ) 项目B1(父级) 项目C1(子级) 项目C2(子级) 项目C3(子级) 项目B2(父级) 项目C4(子级) ...
当从核心数据库获取数据并同时更新同一实体的数据时,fetchRequest 返回 nil let fetchRequest = NSFetchRequest(entityName: "Abc")
我有下面的方法,我通过 NSDate() 来获取今天的所有结果。我试图在午夜到午夜之前得到结果,但似乎不起作用。我注意到我的谓词输出如下: "date >= CAST(460249200.000000
我试图在 tableView 中显示项目,但我的 fetchResult 数组没有显示任何内容。我得到这个 NSLog: 2013-09-13 13:02:01.088 Prototype[67018
关于这个问题,我正在回答我自己的问题。在我看到尽可能多的其他答案之前,我不会接受它。 在过去的几天里,我一直在努力处理下面的代码 - (id)fetchUniqueEntity:(Class)enti
我有一个 Student 实体,它有一个 dateOfBirth 属性。 我想从 Student 实体中获取所有 Students,按出生日期的升序排列,但按月份的降序排列。 例如:属于同一月份的学生
我是 CoreData 的新手,正在尝试编写一个通用函数来查询数据库中的信息。我遇到了一些问题。 我设置了一个名为 NSError *error 的私有(private)变量。我的代码如下所示: @i
我正在使用自定义源表达式 NSExpression(format: "FETCH(FUNCTION($manager, \"customFetchRequestForSourceEntityNamed
我有一个 NSFetchRequest(在 NSFetchedResultsController 中执行)用于以下数据: Person (one-to-many) Encounter Encounte
我的程序有一个带有两个相关表的 sqlite 数据库。一个称为“排名”,另一个称为“要求” 我想从“Requirement”表中获取与“Rank”表中的特定行有关系的所有行。以下是我的代码,它获取整个
我已经就与此相关的不同事情发布了类似的问题,但已经为此苦苦挣扎了大约一周,但无济于事。这一切都归结为这段代码: NSFetchRequest *oldFetchRequest = [[NSFetchR
我是一名优秀的程序员,十分优秀!