我们都知道 以下2个方法是返回一个分组头和脚的尺寸的,最开始想,通过在这里返回0的方式,让第一行数据,能靠近表格顶部
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0;
}
运行后如下图
很明显顶部和第一行数据之间的间隔没达到我们设置的0,最后通过各种设置才发现
只要将0改为一个非0的数值即可实现
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 15;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.1;
}
最终效果如下
解决iOS TableView头部与数据行间距问题
本文探讨了在iOS开发中使用UITableView时遇到的一个常见问题:如何通过设置特定的高度值来消除头部与数据行之间的空白间距。通过提供具体的代码示例,作者详细解释了在`heightForFooterInSection`和`heightForHeaderInSection`方法中返回非零值的重要性,从而实现期望的效果。
1894

被折叠的 条评论
为什么被折叠?



