我正在使用普通样式的UITableView,想知道是否可以防止节标题浮动?
我不想让我的tableview分组。
答案 0 :(得分:1)
不,您无法在简单样式UITableView中更改节标题的行为。
你可以做的不是使用标准的节标题,而是在每个节的顶部添加你自己的额外行,如果你想要相同的外观,使它看起来像标准节标题。
答案 1 :(得分:1)
您可以通过在UIScrollViewDelegate下面实现来实现此目的
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let sectionHeaderHeight: CGFloat = 40
if scrollView.contentOffset.y <= sectionHeaderHeight &&
scrollView.contentOffset.y >= 0 {
scrollView.contentInset = UIEdgeInsetsMake(-
scrollView.contentOffset.y, 0, 0, 0)
} else if scrollView.contentOffset.y >= sectionHeaderHeight {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0)
}
}
根据标题高度更改sectionHeaderHeight值,并且在滚动表格视图时表格标题不会停止。