【发布时间】:2018-01-31 13:35:06
【问题描述】:
我有一个 UI 表格视图,当我滑动单元格时,我删除了单元格,但没有删除 firebase 中的值。我到处搜索,但找不到。如何从我的火力基地的单元格中删除我刷过的阵列。下面是我如何设置我的 firebase 数据库。我要删除的数组是单元格中对应的数组,例如它可能是“-L4BMZBIcYMp_f2LDMbp”等。
还有我必须删除单元格的代码以及在哪里可以找到与单元格对应的数组
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let fliper = self.flipList[indexPath.row]
if let itemID = fliper.item{
FIRDatabase.database().reference().child("Flip").child("..I need to find out how to get child auto id").removeValue(completionBlock: { (error, ref) in
if error != nil {
print("Failed! to delete message")
return
}
//one way of updating the table
self.flipList.remove(at: indexPath.row)
self.tableViewFlips.deleteRows(at: [indexPath], with: .automatic)
})
}`
【问题讨论】:
-
正如您所说,您需要在某处引用该 ID。从您的代码看起来,
itemID应该是您正在寻找的内容,但这一切都取决于您如何对数据进行建模。我们不知道您的数据是什么样的,因此我们无法告诉您此自动 ID 应该来自哪里。但是一些相关的模型对象应该引用它。 -
如果您的数据源是
dictionary或NSDictionary,您只需获取字典的索引即可轻松完成此操作。我不推荐Array,尤其是当您在Firebase调用中填充它时。
标签: ios swift firebase firebase-realtime-database tableview