ios - 使用 UICollectionReusableView 的 UITableView 自定义 header

标签 ios swift uitableview

我目前正在使用 UICollectionReusableView 为表格 View 制作自定义 header 。我面临的问题是这个标题没有像我想要的那样随表格 View 滚动。这是我实现 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 中只有一个背景图像。

是否有任何 bool 选项可以进行设置?否则你会用什么?

最佳答案

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

关于ios - 使用 UICollectionReusableView 的 UITableView 自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50417975/

相关文章:

ios - 如何在 UIPageViewController 上添加按钮?

ios - 如果推送多个 AlertView,Swift 仅显示一个 AlertView

swift - 如何在不使用 ctrl-d 的情况下退出 swift repl?

ios - 通过 NSKeyedArchiver 归档数据时崩溃

swift - setEditing 方法删除按钮不起作用

ios - 您无权使用此服务 iTunes 应用上传错误

ios - 自定义单元格清除背景?

swift - 当我设置 delaysContentTouches = false 时,带有静态单元格的表格不会滚动

ios - swift scene.sks 文件对象不应用 z 旋转值

ios - tableview reloadData 在展开可选值时意外崩溃发现 nil