【问题标题】:How do I reset tableview's contents height after hidden UIView隐藏 UIView 后如何重置 tableview 内容高度
【发布时间】:2016-12-05 13:25:00
【问题描述】:

您好,我正在尝试在隐藏指示器视图之后调整 tableview 的高度。

        self.tableView.reloadData()
        self.refresher.endRefreshing()
        self.indicator.stopAnimating()

        self.indicatorView.isHidden = true

当我将indicatorView 设置为隐藏但TableView 的高度仍有indicatorView 高度的空间。

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    不知何故,您需要实现tableView(_:heightForRowAt:)。例如:

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        // pseudo:
        /*
         if a condition related to hide the indicator (for example response from calling an api to get some data) is true, retrun -for example 100-, else (the response has not been called yet) retrun another value.
         */
    }
    

    您还可以查看indexPath.row 以更改特定的行高:

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        // check if it is the second row:
        if indexPath.row == 1 {
    
        }
    }
    

    因此,在调用self.tableView.reloadData() 之后,应该调用它并为行分配新的高度。

    希望这会有所帮助。

    【讨论】:

    • 谢谢~!对我帮助很大
    • 很高兴为您提供帮助。您可能想查看this answer,了解如何在同一个 tableview 中显示不同的单元格。
    • 非常感谢,我会试试这个并在这里更新结果! :)
    【解决方案2】:

    在堆栈视图中嵌入 tableViewindicatorView

    类似于this answer,但使用Vertical Axis。

    【讨论】:

    • 感谢回复~!
    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2017-05-27
    • 2012-02-23
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多