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

后端 未结 3 1870
野的像风
野的像风 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 21:56

    It's a fairly straightforward process:

    In general, a datasource for tableViews is an array. That array is built from dictionaries read from Firebase snapshots - or an array of objects built from the snapshots (recommended).

    So here's an example that matches your Firebase structure (this was populated from a single node from a snapshot)

    class Exercise {
        key: "KWc7RTuOe5PefiMM2tL"
        bodyPart: "Legs"
        exerciseName: "Test 3 "
        userId: "8rHmyTxdocTEvk1ERiiavjMUYyD3"
    }
    

    Then, when the user swipes row 3 for example, retrieve the Exercise object from the array, row3.

    let theObject = ExerciseArray[3]
    let parentNode = theObject.key
    let ref = rootNode.child(parentNode)
    ref.setValue(nil)
    

    and you're done.

提交回复
热议问题