【发布时间】:2016-09-24 09:02:29
【问题描述】:
好的,我正在按照本教程 (https://www.raywenderlich.com/139322/firebase-tutorial-getting-started-2) 使用 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)
}
}
它抛出错误:
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:无效 第 0 节中的行数。包含在第 0 节中的行数 更新后的现有节(8)必须等于 更新前该部分中包含的行 (8),加号或减号 从该部分插入或删除的行数(0 插入, 1 已删除)并加上或减去移入或移出的行数 该部分(0 移入,0 移出)。'
【问题讨论】:
标签: ios firebase firebase-realtime-database