[英]Table view does not update when calling from completion handler
I built a rename dialog to change selected list (table) entries. 我建立了一个重命名对话框来更改选定的列表(表)条目。 The rename dialog has a delagate in the main view.
重命名对话框在主视图中具有delagate。 If the dialog is closed by clicking "save" then some database operations should be executed and the table must be refreshed:
如果通过单击“保存”关闭对话框,则应执行一些数据库操作,并且必须刷新表:
func finishedShowing(_ vc : UIViewController, _ result : Bool) {
if result {
vc.dismiss(animated: true, completion: {
if vc is RenameViewController {
// do something in the database and update the table model
self.refreshLibrary()
}
})
}
}
private func refreshLibrary() {
self.tableView.reloadData()
}
My problem is that the database is changed successfully so the completion handler is triggered correctly and also the table model (an array of strings in my case) is changed (I debugged it) but the table view does not update. 我的问题是数据库已成功更改,因此完成处理程序已正确触发,并且表模型(在我的情况下为字符串数组)也发生了更改(我对其进行了调试),但表视图未更新。 It only shows the old version.
它仅显示旧版本。
Call the reload function inside the main thread: 在主线程中调用reload函数:
private func refreshLibrary() {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.