返回tableview后,Tableview重新加载行

问题描述 投票:0回答:2

我回到tableview后试图重新加载行。

在第一次重新加载tableview中,我可以使用下面的代码和数据重新加载行。

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

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

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

谁有任何想法?

ios swift uitableview tableviewcell reloaddata
2个回答
0
投票

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

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

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


0
投票

试试这个肯定会有效。

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

© www.soinside.com 2019 - 2024. All rights reserved.