[英]How to remove a reference autoId value in a UItableView from Firebase tree in Swift?
我有一個表視圖,其中加載了Firebase的消息。 存儲數據很容易,但是嘗試刪除具有autoID的特定節點使我很麻煩。
我知道我必須獲得對第一個節點(在本例中為Posts
的引用,但是如何獲取下一個節點作為引用? 在這種情況下,此節點是autoId。 下面是代碼。
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
print(messages)
print(indexPath.row)
var messageIndexRef = postData[indexPath.row]
print(messageIndexRef)
ref?.child("Posts").child("how do I get this auto ID?").removeValue(completionBlock: { (error, ref) in
if error != nil {
print("error \(error)")
}
})
MessagesTableView.reloadData()
}
}
您將需要保留一個字典,該字典將表視圖的每一行/索引映射到Firebase中相應項目的鍵。
從您共享的代碼段中可以看到,它與postData
處於同一級別。 一個持有密鑰,另一個持有每一行的值。
如果在從Firebase讀取數據時(同時獲得值)同時構建了兩個字典,則可以使用帶鍵的字典來確定用戶單擊的行的key
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.