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