简体   繁体   English

回到tableview后Tableview重新加载行

[英]Tableview reload row after come back tableview

I am trying to reload row after come back to tableview. 我试图重新加载行后回到tableview。

In first reload tableview I can reload row with below code and data effected. 在第一个重新加载tableview中,我可以使用以下代码和数据重新加载行。

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

When I come to previous view with back button and then open same tableview again I can not reload row. 当我使用后退按钮进入上一个视图,然后再次打开相同的tableview时,我无法重新加载行。

Code is working I can see when reload code calls cellForRowAt indexPath function but data not effect it. 代码可以正常工作,我可以看到重新加载代码何时调用cellForRowAt indexPath函数,但是数据不起作用。

Any one has any idea? 有人知道吗?

Try to do same code in viewWillAppear function. 尝试在viewWillAppear函数中执行相同的代码。 Something like 就像是

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

But you need to pass back information about what indexPath was clicked. 但是您需要传回有关单击了什么indexPath的信息。

试试这个,肯定会起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM