iOS 15+ 分组UITableView底部存在多余小空白问题求助
解决iOS 15及以上分组UITableView底部多余空白问题
问题描述
在iOS 15及以上系统中,分组样式的UITableView底部出现一处多余小空白,已尝试以下代码但未解决:
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { .leastNonzeroMagnitude } tableView.sectionHeaderTopPadding = .leastNonzeroMagnitude
问题示例:
Storyboard设置截图:
可行解决方案
方案1:设置全局tableFooterView
给UITableView添加一个高度趋近于0的空白footer视图,覆盖系统默认的底部留白:
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: .leastNonzeroMagnitude))
方案2:实现section footer代理方法并返回空视图
同时实现viewForFooterInSection和heightForFooterInSection方法,确保footer为空且高度最小:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { return UIView() } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return .leastNonzeroMagnitude }
方案3:检查Storyboard配置
从截图确认以下设置:
- 确保UITableView的
Style为Grouped - 检查section footer的默认高度是否被设置为非0值,若有则改为0
- 确认UITableView的
Content Insets未添加额外底部内边距
方案4:临时调整contentInset(不推荐优先使用)
若上述方法均无效,可手动调整底部内边距抵消空白:
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: -8, right: 0)
注:此方法为临时适配手段,后续系统版本更新可能导致适配问题,建议优先使用前三种方案。
内容的提问来源于stack exchange,提问作者Mixorok
相关产品推荐
相关产品推荐

