【发布时间】:2018-10-17 03:47:53
【问题描述】:
我尝试删除单元格(向左滑动)并从 Firebase 数据库和存储中删除数据。使用此代码:
struct Records {
let title: String
let source: String
var length: String
let recordUrl: String
let username: String
init(dictionary: [String: Any]) {
self.title = dictionary["title"] as? String ?? ""
self.source = dictionary["source"] as? String ?? ""
self.length = dictionary["length"] as? String ?? ""
self.recordUrl = dictionary["recordUrl"] as? String ?? ""
self.username = dictionary["username"] as? String ?? ""
}
}
我有一个变量
var records = [Records]()
试图删除单元格
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
guard let uid = Auth.auth().currentUser?.uid else { return }
if (editingStyle == .delete) {
records.remove(at: indexPath.item)
tableView.deleteRows(at: [indexPath], with: .fade)
Database.database().reference().child("users").child(uid).child("records").removeValue()
}
}
Firebase JSON enter image description here
我需要删除“记录”中的项目(在我的 TableView 中显示为单元格),但现在使用我的代码我删除了整个“记录”
【问题讨论】: