美文网首页Swift编程
UITableView tableHeader/sectionH

UITableView tableHeader/sectionH

作者: 追风筝的荧火虫 | 来源:发表于2019-11-07 16:11 被阅读0次

问题描述

swift 5 当push到一个包含UITableView的viewController的时候,当initTableView.plain 或者 .grouped 时有时候会出现sectionHeaderView/footerHeaderView 或者 tableHeaderView/tableFooterView 的偏移,这个偏移即使去设备tableView.contentInset也是达不到预期的效果的,(其实不算是偏移,是tableView默认值,所以会看到明明没有设置tableHeader.height, 也没有设置sectionHeader.height 和 sectionFooter.height ,却出现了)

具体表现为:

.plain sectionHeader/sectionFooter位置问题 .grouped tableHeader/tableFooter位置问题
可以看到这个footer一直在这里停留 没有设置tableHeader,但可以看到这里出现了

解决办法:

直接给它们设置一个最小值来去掉这个默认值:

// for tableHeaderView and tableFooterView
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))

// for sectionHeaderView and sectionFooterView
tableView.sectionHeaderHeight = CGFloat.leastNormalMagnitude
tableView.sectionFooterHeight = CGFloat.leastNormalMagnitude

相关文章

网友评论

    本文标题:UITableView tableHeader/sectionH

    本文链接:https://www.haomeiwen.com/subject/dgjvbctx.html