【问题标题】:Tableview reload row after come back tableview返回tableview后tableview重新加载行
【发布时间】:2017-02-04 18:08:49
【问题描述】:

回到 tableview 后我正在尝试重新加载行。

在第一次重新加载 tableview 时,我可以重新加载行并影响以下代码和数据。

let indexPath = IndexPath(row: 2, section: 0)
        tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)

当我使用后退按钮返回上一个视图然后再次打开相同的 tableview 时,我无法重新加载行。

代码正在工作我可以看到重新加载代码何时调用 cellForRowAt indexPath 函数但数据不影响它。

有人知道吗?

【问题讨论】:

    标签: ios swift uitableview tableviewcell reloaddata


    【解决方案1】:

    尝试在 viewWillAppear 函数中执行相同的代码。像

    override func viewWillAppear(_ animated: Bool) {
            tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
        }
    

    但是您需要传回有关单击了哪个 indexPath 的信息。

    【讨论】:

      【解决方案2】:

      试试这个 它肯定会奏效。

      self.tableView.estimatedRowHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.estimatedSectionFooterHeight = 0;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多