Grouped UITableView shows blank space when section is empty

后端 未结 11 591
别跟我提以往
别跟我提以往 2020-12-30 23:44

I have a grouped UITableView where not all sections may be displayed at once, the table is driven by some data that not every record may have. My trouble is that the record

11条回答
  •  无人及你
    2020-12-31 00:04

    Here is the solution that worked for me

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
        switch (section) {  
          case 1: case 3: case 5: return 20.0f; break;
          default: return 0.01f; // for some reason 0 is not accepted - give something :)
        }
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        switch (section) {  
          case 1: case 3: case 5: return 20.0f; break;
          default: return 0.01f; // for some reason 0 is not accepted - give something :)
        }
    }
    

提交回复
热议问题