gpt4 book ai didi

swift - 如何在删除 firebase 中的数据后刷新 TableViewCell?

转载 作者:可可西里 更新时间:2023-11-01 01:52:25 26 4
gpt4 key购买 nike

我想在通过滑动操作表删除对话后刷新我的对话(表格 View 单元格)。

我试图在删除数据后重新加载 TableView ,但它不起作用。还有异步。

 // Swipe Action Sheet solution
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{

// Write action code for the Flag
let deleteAction = UIContextualAction(style: .normal, title: "Löschen", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
let ref = Database.database().reference()
ref.child("users").child((self.currentUser?.uid)!).child("conversations").child((self.items[indexPath.row].user.uid)!).removeValue()
DispatchQueue.main.async {
self.tableView.reloadData()
}
success(true)
})
deleteAction.backgroundColor = .red
return UISwipeActionsConfiguration(actions: [deleteAction])

}

预先感谢您的帮助!

最佳答案

如果没有任何错误,您必须在 removeValue 方法的完成 block 中重新加载数据。此外,在重新加载数据之前,您必须从 items 数组中删除项目

.removeValue { error,_ in
if error == nil {
self.items.remove(at: indexPath.row)
self.tableView.reloadData() // self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
success(error == nil)
}

关于swift - 如何在删除 firebase 中的数据后刷新 TableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53872205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com