ios - tableView(_:heightForHeaderInSection:) 不工作
问题描述
我正在UITableView
我的UIViewController
. 我已经能够让我的文本以自定义方式显示UITableViewCell
,但我找不到在单元格之间放置间距的方法。
我已经尝试实现tableView(_:heightForHeaderInSection:)
,但似乎没有调用它,因为我试图放入打印语句以查看它是否运行。
解决方案
我遇到了heightForHeaderInSection不起作用的问题,但是在我设置 viewForHeaderInSection 之后,高度就可以正常工作。确保您已在部分中设置视图标题。
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
view.backgroundColor = .white
return view
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
推荐阅读
- angular - Angular 8 如何获取可用于动态加载的组件数组?
- kubernetes - Kubernetes:kube-scheduler 没有为 pod 分配正确评分节点
- reactjs - 即使 console.log 输出显示数据,React Axios get 方法也不显示任何数据
- python - 我可以在 openbox 中使用 _NET_WM_WINDOW_TYPE_DOCK EWHM 扩展吗?
- javascript - 获取 ical url
- ios - Visual Studio Xamarin 自动预配不起作用
- java - 在 REST API 中自定义/修补 400 响应
- python-3.x - 有没有可能使用 tkinter 框架创建一个 hitbox 的方法?
- c# - 数的负指数
- python - 如何获得带孔的二进制掩码的边界坐标?