hachinoBlog

hachinobuのエンジニアライフ

titleForHeaderInSectionでsectionNameKeyPathで指定したカラム以外をセクションタイトルとして指定する方法

UITableViewのtitleForHeaderInSectionでNSFetchedResultsControllerから対象のテーブルオブジェクト取得

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{
    //Sessionsテーブルのオブジェクトの取得 _fetchedResultsControllerはNSFetchedResultsControllerのインスタンス変数
    Sessions *session = [[[[_fetchedResultsController sections] objectAtIndex:section] objects] objectAtIndex:0];
}

あとはsectionNameKeyPathとsetSortDescriptorsで設定したカラムとの順序が崩れないように注意しつつ
好きなカラムをセクションのタイトルにできる