How to hide a section in UITableView?

前端 未结 12 2201
梦如初夏
梦如初夏 2020-12-05 00:32

There are some section in the table that does not contain any data and would like to hide that section.

How to do this?

12条回答
  •  情歌与酒
    2020-12-05 00:52

    You can set the particular section rows height to 0. Also, with the section header if you want. Datasource would still be there, only not showing up.

    Section Rows

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.section == 0) {
            if (_shouldHidden) {
                return 0.0;
            }
            else {
                return 55.0;
            }
        }
        else {
            return 55.0;
        }
    }
    

提交回复
热议问题