How can I delete a specific child node in Firebase from UITableViewCell using Swift

后端 未结 3 1888
野的像风
野的像风 2020-12-21 21:36

I have a UITableView which looks like this image

\"this.

When I swipe to delete th

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 22:08

    Following on from what MHDev has already answered:

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
    
            if let exerciseName = exercises[indexPath.row].exerciseName {
    
                let ref = FIRDatabase.database().reference().child("userExercises")
    
                ref.queryOrdered(byChild: "exerciseName").queryEqual(toValue: exerciseName).observe(.childAdded, with: { (snapshot) in
    
                    snapshot.ref.removeValue(completionBlock: { (error, reference) in
                        if error != nil {
                            print("There has been an error:\(error)")
                        }
                    })
    
                })
    
            }
    
            exercises.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .left)
        }
    }
    

提交回复
热议问题