如果可能,请帮助我。当用户使用 removeValue 方法调用 delete editingStyle 函数时,我想删除 tableView 中的数据。到目前为止,我有一个项目类:
class Item : NSObject {
var itemName: String!
var itemDate: String!
var itemID: String!
init(itemName: String, itemDate: String, itemID: String) {
self.itemName = itemName
self.itemDate = itemDate
self.itemID = itemID
}
init(snapshot: FIRDataSnapshot) {
let snapshotValue = snapshot.value as? NSDictionary
self.itemName = snapshotValue!["itemName"] as! String
self.itemDate = snapshotValue!["itemDate"] as! String
self.itemID = snapshotValue!["itemID"] as! String
}
func toAnyObject() -> [String: AnyObject] {
return ["itemName": itemName as AnyObject, "itemDate": itemDate as AnyObject, "itemID": itemID as AnyObject]
}
}
现在我想删除用户 itemID 中的值,但我不确定从这里去哪里:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
guard let uid = FIRAuth.auth()?.currentUser?.uid else {
return
}
let item = itemArray[indexPath.row]
let itemID = databaseRef.child("ItemID")
databaseRef.child("users").child(uid).child("usersList").child(itemID).removeValue()
我认为您缺少“删除”编辑样式,并且需要对引用进行一些更改。试试这个:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
guard let uid = FIRAuth.auth()?.currentUser?.uid else {
return
}
let item = items[indexPath.row]
let itemID = ref.child("users").child(uid).child("usersList").child("ItemID")
if editingStyle == .delete {
item.ref?.removeValue()
}
}
关于ios - 从 Firebase 数据库 Swift 3 中删除子数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42912420/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |