首页 > 解决方案 > 使用 UICollectionReusableView 的 UITableView 自定义标题

问题描述

我目前正在使用 UICollectionReusableView 为 tableview 制作自定义标题。我面临的问题是这个标题没有像我想要的那样随着表格视图滚动。以下是我实现 headerview 的方式:

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; 
}

在 UICollectionReusableView .swift 文件中有默认代码,在 .xib 中只有一个 backgroundImage。

是否有任何布尔选项来设置它?否则你会用什么?

标签: iosswiftuitableview

解决方案


如果不是,请尝试将 UITableView 的style属性更改为。.plain.grouped样式将在滚动时将标题保留在屏幕上。


推荐阅读