【问题标题】:UITableView - footer of last section scrolls off the bottom of the screen. How to prevent?UITableView - 最后一节的页脚滚动到屏幕底部。如何预防?
【发布时间】:2017-08-23 14:57:19
【问题描述】:

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

如何解决? 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.

【问题讨论】:

    标签: ios swift uitableview footer


    【解决方案1】:

    我认为它被标签栏挡住了。
    如果使用 storyborad,请重置 tableView 的约束。
    如果没有,您需要正确设置 tableView 的框架。

    【讨论】:

    • 确保表格视图的底部约束链接到Bottom Layout Guide,而不是Container Margin
    • 啊!我还没有在任何地方设置明确的约束。但是“标签栏”背后的含义很有意义。我会追究的。谢谢。
    【解决方案2】:

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

    方法 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)
    }
    

    【讨论】:

    • 我使用了 TableViewController,但无法找到调整 tableView 大小的方法,如 vids 所示(感觉不错!)。我戳了一下能够使用方法 3,这似乎有效。有一天,我会明白的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2013-08-05
    • 2015-10-24
    • 2013-04-29
    • 1970-01-01
    • 2021-04-05
    • 2012-10-01
    • 2013-08-19
    • 2016-04-17
    相关资源
    最近更新 更多