좋아, 나는이 튜토리얼 (https://www.raywenderlich.com/139322/firebase-tutorial-getting-started-2)을 사용하여 tablebase에서 Firebase로 행을 삭제했지만 작동하지 않는 것으로 보인다. 내 코드는 다음과 같이Firebase + Tableview에서 행 삭제하기
override func viewDidLoad() {
super.viewDidLoad()
configureDatabase()
}
func configureDatabase() {
self.ref = FIRDatabase.database().reference()
if let user = FIRAuth.auth()?.currentUser {
self.ref.child("mileage").queryOrderedByChild("user").queryEqualToValue(user.uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
self.mileageDatabase.insert(snapshot, atIndex: 0)
self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: .Automatic)
})
} else {
}
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let row = self.mileageDatabase[indexPath.row]
row.ref.removeValue()
self.tableView.deleteRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row, inSection: 0)], withRowAnimation: .Automatic)
}
}
그것은 오류가 발생합니다 :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
어떻게 할 수 있습니까? – Learn2Code