我目前正在使用 UICollectionReusableView 为表视图创建自定义标头。我面临的问题是这个标题没有像我想要的那样随表视图滚动。以下是我实现标题视图的方式:
func numberOfSections(in tableView: UITableView) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = Bundle.main.loadNibNamed("StoresListHeaderView", owner: self, options: nil)?.first as! StoresListHeaderView;
return headerView;
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 170;
}
在UICollectionReuseableView.swift文件中有默认代码,在.xib中只有一个背景图像。
是否有任何布尔选项来设置它?否则你会用什么?
尝试将 UITableView 的style
属性更改为.plain
(如果不是(。.grouped
样式将在滚动时将标题保留在屏幕上。