UITableView - 最后一部分的页脚滚出屏幕底部。如何预防?

UITableView - footer of last section scrolls off the bottom of the screen. How to prevent?

我有一个 grouped UITableView。我已经实现了 tableView(:titleForHeaderInSection:)tableView(:titleForFooterInSection :)。当我滚动很长 table 时,我可以看到节的页眉和页脚包含预期的数据。当我到达 table 的底部并向上拖动以查看最后一部分的页脚时,它具有正确的数据,但是当我松开手指时,页脚向下滚动到屏幕底部和视线之外。最后一节的最后一个单元格出现在屏幕底部,而不是最后一节的页脚。

如何解决? There's the last section and its footer. My finger is still on the screen

When I release my finger, the final footer slides off the bottom of the screen.

我认为它被标签栏阻止了。
如果使用故事板,请重置 tableView 的约束。
如果不是,则需要正确设置 tableView 的框架。

您可以通过考虑以下方法之一来解决滚动内容问题。

方法 1: 通过从情节提要中正确设置 tableView 框架及其底部约束来解决问题的自然方法。

更新:

方法 2:您可以在 viewDidLayoutSubviewsviewWillLayoutSubviews

中验证您的 tableView 框架
 override func viewDidLayoutSubviews() {
     tableView.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: tableView.frame.height - (tabBarController?.tabBar.frame.size.height)!)
 }

方法 3:通过调整滚动视图 insets 来设置 tableView 框架。

override func viewDidLayoutSubviews() {
    tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: (tabBarController?.tabBar.frame.size.height)!, right: 0)
}