UITableView Not Respecting heightForHeaderInSection/heightForFooterInSection?

后端 未结 9 1664
臣服心动
臣服心动 2020-12-09 02:57

I have a UITableView where in some instances, certain sections have zero rows. My goal is that when this is true, I don\'t want any wasted space in the table view, it should

9条回答
  •  感情败类
    2020-12-09 03:51

    This is a bit tricky, as 0.0f value is not accepted. but anything close enough to zero will do the trick. If You decide not to be pixel perfect and want the round numbers, then 1.0f will do almost the same, as 1px difference in height will be fairly noticable.

    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        if(section == 1 )
            return 0.000001f;
        else return 44.0f; // put 22 in case of plain one..
    }
    
    -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        return 0.000001f; //removing section footers
    }
    

提交回复
热议问题