简体   繁体   English

从完成处理程序调用时,表视图不会更新

[英]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.

相关问题 调用“UNUserNotificationCenter”的完成处理程序时崩溃 - Crash when calling completion handler for `UNUserNotificationCenter` 从完成处理程序调用父函数的返回 - Calling return of parent function from the completion handler 从 firebase 调用数据所需的完成处理程序? - Completion handler needed for calling data from firebase? 弹出视图时,完成处理程序会如何处理? - What happens to a completion handler when a view is popped? 具有完成处理程序的功能,执行何时完成? - Function with completion handler, when does execution finish? 当授权应用程序时,Facebook iOS SDK不调用完成处理程序 - Facebook iOS SDK not calling completion handler when authorized app 从Timer选择器函数Swift调用函数的完成处理程序 - Calling completion handler of a function from Timer selector function Swift UIActivityViewController完成处理程序在视图控制器从屏幕上消失之前执行 - UIActivityViewController completion handler executes before the view controller disappears from the screen 如何在视图中显示来自 Swift 完成处理程序的返回值? - How to display in a View a returned value from a completion handler in Swift? 成就完成处理程序无法检测到没有可用的Internet连接 - Achievement Completion Handler does not detect when no Internet connection is available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM