簡體   English   中英

回到tableview后Tableview重新加載行

[英]Tableview reload row after come back tableview

我試圖重新加載行后回到tableview。

在第一個重新加載tableview中,我可以使用以下代碼和數據重新加載行。

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

當我使用后退按鈕進入上一個視圖,然后再次打開相同的tableview時,我無法重新加載行。

代碼可以正常工作,我可以看到重新加載代碼何時調用cellForRowAt indexPath函數,但是數據不起作用。

有人知道嗎?

嘗試在viewWillAppear函數中執行相同的代碼。 就像是

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

但是您需要傳回有關單擊了什么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