viewForFooterInSection 不让 UITableView 页脚粘在底部?
Posted
技术标签:
【中文标题】viewForFooterInSection 不让 UITableView 页脚粘在底部?【英文标题】:viewForFooterInSection not making UITableView Footer stick to bottom? 【发布时间】:2018-04-11 23:12:57 【问题描述】:是的,我已经阅读了很多关于这个问题的其他帖子,但没有一个解决方案对我有用!
基本上,当我使用 viewForFooterInSection 和 heightForFooterInSection 时,生成的页脚“浮动”
viewDidLoad 和 FooterView 代码:
override func viewDidLoad()
super.viewDidLoad()
setupNaviationBarStyles()
setUpNavBarButtons()
navigationItem.title = "Kindle"
tableView.register(BookCell.self, forCellReuseIdentifier: "cellId")
tableView.backgroundColor = UIColor.lightGray
fetchBooks()
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
let view = UIView()
view.backgroundColor = .red
return view
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
return 50
问题似乎是 iPhone x 特有的?在 iPhone 7 模拟器中,上述代码完美运行:
我尝试在 viewDidLoad 中创建自定义视图,就像许多其他线程建议的那样,但还没有这样的运气:
let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width:
tableView.frame.size.width, height: 40))
view.backgroundColor = .red
self.tableView.tableFooterView = view
感谢有关此问题的任何帮助,似乎解决方案可能很简单,但我已经研究了一段时间,但在使用 iPhone x 进行模拟时没有发现任何非常有效的方法。
干杯!
【问题讨论】:
这个解决方案对我有用***.com/a/47070782/8366535 【参考方案1】:这是苹果的错误,不是你的。他们完全没有考虑 iPhone X 的含义。
您真正能做的就是将导航控制器的isToolbarHidden
设置为false
,即使您没有工具栏内容。这将占用 home 指示器后面的空间,并且桌子看起来不错。
【讨论】:
请向 Apple 提交错误报告。以上是关于viewForFooterInSection 不让 UITableView 页脚粘在底部?的主要内容,如果未能解决你的问题,请参考以下文章
当我快速单击 viewForFooterInSection 上的按钮时如何获取单元格数据
UITableView viewForFooterInSection 仅在滚动后显示
如何自定义 UITableView 中部分的 UIView?