현재 Firebase를 사용하여 사람들의 데이터와 그에 대한 세부 정보를 저장하고 있습니다. 내가있는 tableView를 채우는 데이터베이스에서 정보를 검색하는 방법입니다 : 내 사용자의TableView에서 Firebase 노드를 삭제하는 방법
let ref = FIRDatabase.database().reference().child("Users")
ref.observeEventType(.ChildAdded, withBlock:
{ (snapshot) in
if let firstname = snapshot.value?.objectForKey("firstname"), lastname = snapshot.value?.objectForKey("lastname")
{
let fullname = "\(firstname) \(lastname)"
self.names.append(fullname)
self.tableView.reloadData()
}
}, withCancelBlock: nil)
각각 고유 한 ID를 가지고 있으며, 그에 따라 삭제하려고 해요. 지금까지 난 단지 데이터베이스에서있는 tableView의 끝에서가 아니라 내 사용자를 삭제 : 내 observePeople() 함수에서
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if editingStyle == .Delete
{
names.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
//Delete from firebase
}
}
을 아이가과 같이 제거하면 나는 관찰 할 수있는 코드를 구현 :
ref.observeEventType(.ChildRemoved, withBlock:
{ (snapshot) in
if let firstname = snapshot.value?.objectForKey("firstname"), lastname = snapshot.value?.objectForKey("lastname"), dateOfBirth = snapshot.value?.objectForKey("Date of Birth"), zipcode = snapshot.value?.objectForKey("Zipcode")
{
print("We deleted the person \(firstname) \(lastname) with the details: \(dateOfBirth), \(zipcode)")
}
}, withCancelBlock: nil)
그렇다면 누군가가 tableView에서 스 와이프하여 삭제할 때 ID를 기반으로 정확한 사용자를 삭제하려면 어떻게해야합니까?
그렇습니다. 정확히 나무 모양입니다. –