【发布时间】:2017-01-24 20:57:00
【问题描述】:
我正在尝试从 Firebase 中删除一个项目,但我遇到了一个奇怪的问题。 这是函数:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
//delete item from array
itemArray.remove(at: indexPath.row)
// delete from database
var itemRef = FIRDatabaseReference()
ref = FIRDatabase.database().reference()
let userID = FIRAuth.auth()?.currentUser?.uid
let idDel = itemArray[indexPath.row].itemID
itemRef = self.ref.child(userID!).child("ShoppingCart").child(idDel!)
itemRef.removeValue()
//delete row
cartTable.deleteRows(at:[indexPath], with: .fade)
}
}
问题是每次我删除一个项目时,Firebase 中都会删除下一个项目,而不是我选择的项目。当我到达数组的末尾时,我收到错误“索引超出范围”。我猜它与索引路径/数组位置有关?
提前致谢!
【问题讨论】:
-
能否在每个阶段注销 indexPath 看看哪里出错了?