1
我有显示自定义对象,每个代表戏剧作品的列表的核心数据的应用程序。动态地将UITableView分解成任意部分?
每届展会对象有一堆的属性 - 名称,标识,开业至今,表演类型。
我可以取回他们罚款,按类型排序就好了 - 但我想每个节目类型是在表自己的部分。
我不知道提前多少节目类型将在结果集进行表示,所以我不知道最初的numberofsections应该是什么。
所以我想的问题是 - 我将如何去划分的结果集为按类型分组的部分?
目前我在做这个:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Show" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"type" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
哎呦,这是一个非常简单的修复,我只是需要加入: - (的NSString *)的tableView:(UITableView的*)的tableView titleForHeaderInSection:(NSInteger的)部分{// 显示作者的名字作副标题。 返回[[[self.fetchedResultsController部分] objectAtIndex:部分]名称]; } 并改变该位: NSFetchedResultsController * aFetchedResultsController = [[NSFetchedResultsController的alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@ “类型” cacheName:@ “根”]; – 2011-05-15 01:58:38