我正在使用NSFetchedResultsController来驱动我的UITableViewController的数据.我正在获取的托管对象的简化版本看起来像这样(例如):
Person: -(BOOL)hasPet; -(BOOL)hasDog;
基本上,我希望我的表只显示那些有宠物的Person对象.这很简单,我可以使用谓词.现在,对于那些hasPet == YES的人,我想把它们放在表中的2个部分中,第一部分是hasDog == YES,第二部分是hasDog == NO.这是我有点模糊的地方.这是我配置结果控制器的地方,希望有人可以帮助引导我朝着正确的方向前进.
- (NSFetchedResultsController *)fetchedResultsController { if (nil != fetchedResultsController) { return fetchedResultsController; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Homework" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hasPet == %@",[NSNumber numberWithBool:YES]]; [fetchRequest setPredicate:predicate]; NSSortDescriptor *dogDescriptor = [[NSSortDescriptor alloc] initWithKey:@"hasDog" ascending:YES]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:dogDescriptor,sortDescriptor,nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil]; aController.delegate = self; self.fetchedResultsController = aController; // Release things return fetchedResultsController; }
是一个排序描述符,我需要关注我的注意力吗?
@H_502_10@