例)セクション[2]を隠す
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 2) { // セクション[2]内おセルをすべて非表示
cell.hidden = YES;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 2) { // セクション[2]内のセルの高さをすべて0に
return 0;
} else {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
}高さを0にするだけだと下のセルに重なって表示されてしまうので合わせてhiddenにもしておく。これはクリッピングすれば不要かもしれない。
追記)セクションヘッダがある場合はこれも高さ0にしてやる。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 2) {
return 0;
} else {
return [super tableView:tableView heightForHeaderInSection:section];
}
}


Responses
Leave a Response