あなたが言っていることから、グループ化されたテーブルビューを使用してみてください。簡単な概要については、このリンクを確認し、グループ化されたテーブル ビュー セクションに移動してください。
編集でこの例が見つかりました:
それはあなたが探しているもののようです。また、非常にクールなアイデアです。
独自のカスタム ヘッダー行を作成し、それを各セクションの最初の行として配置するだけです。現在そこにある UITableView またはヘッダーをサブクラス化することは、おそらく非常に苦痛であり、現在の方法で簡単にアクションを取得できるかどうかはわかりません。ヘッダーのように見えるようにセルを簡単に設定し、セルが含まtableView:didSelectRowAtIndexPath
れるセクションを手動で展開または折りたたむように設定することができます。
私があなただったら、各セクションの「消費された」値に対応するブール値の配列を保存します。次に、tableView:didSelectRowAtIndexPath
各カスタム ヘッダー行でこの値を切り替えてから、その特定のセクションをリロードすることができます。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
///it's the first row of any section so it would be your custom section header
///put in your code to toggle your boolean value here
mybooleans[indexPath.section] = !mybooleans[indexPath.section];
///reload this section
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}
}
次に、数値を設定して値numberOfRowsInSection
を確認しmybooleans
、セクションが展開されていない場合は 1 を返し、展開されている場合はセクション内の項目数に 1 を加えた値を返します。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (mybooleans[section]) {
///we want the number of people plus the header cell
return [self numberOfPeopleInGroup:section] + 1;
} else {
///we just want the header cell
return 1;
}
}
cellForRowAtIndexPath
また、任意のセクションの最初の行のカスタム ヘッダー セルを返すように更新する必要があります。