gpt4 book ai didi

swift - 从 firebase 数据库中删除

转载 作者:行者123 更新时间:2023-11-30 12:16:22 25 4
gpt4 key购买 nike

我正在为练习项目创建在线订购服务。我最近读到的两件事是编辑表格 View 功能。当我滑动删除项目时,它不会从数据库中取出正确的项目。另外,如果数组中只有一项,而我尝试删除它,则会使其崩溃。有人知道这是怎么回事吗?

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

orderNumber.remove(at: indexPath.row)
itemsArray.remove(at: indexPath.row)
priceArray.remove(at: indexPath.row)
quantityArray.remove(at: indexPath.row)

databaseRef.child("Users/\((authRef.currentUser?.uid)!)/Order/\(orderNumber.remove(at: indexPath.row))").removeValue { (error, ref) in
if error != nil {
print(error?.localizedDescription as Any)
} else {

}
}
}

最佳答案

看起来你只需要在删除它之前检查数组计数:-

if orderNumber.count > indexPath.row {
orderNumber.remove(at: indexPath.row)
}
if itemsArray.count > indexPath.row {
itemsArray.remove(at: indexPath.row)
}
if priceArray.count > indexPath.row {
priceArray.remove(at: indexPath.row)
}
if quantityArray.count > indexPath.row {
quantityArray.remove(at: indexPath.row)
}

关于swift - 从 firebase 数据库中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396206/

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