【发布时间】:2009-12-31 18:29:12
【问题描述】:
我正在尝试使用此处的示例为核心数据填充表添加 A-Z 索引:http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/
但是,我无法确定可以在核心数据帮助程序头文件中设置 sectionNameKeyPath 属性的位置:
我需要像在 CoreDataBooks 中那样制作 NSFetchedResultsController 吗?或者我可以在这里的某个地方添加它吗?!抱歉我的无知,任何想法/帮助将不胜感激(这是把我的头发扯掉的第三天)。
+(NSMutableArray *) searchObjectsInContext: (NSString*) entityName : (NSPredicate *) predicate : (NSString*) sortKey : (BOOL) sortAscending : (NSManagedObjectContext *) managedObjectContext
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
// If a predicate was passed, pass it to the query
if(predicate != nil)
{
[request setPredicate:predicate];
}
// If a sort key was passed, use it for sorting.
if(sortKey != nil)
{
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:sortAscending];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
}
NSError *error;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
[request release];
return mutableFetchResults;
}
【问题讨论】: