ios - 从 Tableview 中删除值而不希望从 firebase 得到答案
问题描述
当我从 tableView 中删除一个值时,我正在尝试执行代码,但这不起作用..
事实上,我想从 firebase 下载当前值,然后从 firebase 中减去另一个框中给出的值,并且 autoID 包含在我的 tableView 中。所以我必须从 Firebase 下载 2 个信息,然后执行减法并将新值发送到 firebase,然后再擦除我的 tableView 的线。
我目前有这段代码:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{
if let user = Auth.auth().currentUser{
// user is connect
let ref = Database.database().reference()
let userID = Auth.auth().currentUser?.uid
//soustraire les valeurs au total exp
ref.child("Experience").child(userID!).observeSingleEvent(of: .value) {(snapshot) in
if let value = snapshot.value as? [String:String]{
let value = snapshot.value as? NSDictionary
let ldg_day = value?["LDG_DAY"] as? String ?? "0"
let ldg_night = value?["LDG_NIGHT"] as? String ?? "0"
let apch_ifr = value?["APCH_IFR"] as? String ?? "0"
self.oldIntDayLdg = Int(ldg_day) ?? 0
/*self.intLdgNight = Int(ldg_night) ?? 0
self.intApchIfr = Int(apch_ifr) ?? 0*/
self.oldStringDayLdg = ldg_day
/*self.currentStringLdgNight = ldg_night
self.currentStringApchIfr = apch_ifr*/
print("getUserInfo : IntDay : \(self.oldIntDayLdg) & StringDay : \(self.oldStringDayLdg)")
}
}
ref.child("flights").child(userID!).child(datas[indexPath.row].AutoId).observeSingleEvent(of: .value) {(snapshot) in
if let value = snapshot.value as? [String:String]{
let value = snapshot.value as? NSDictionary
let this_flight_ldg_day = value?["LDG_DAY"] as? String ?? "0"
/*let ldg_night = value?["LDG_NIGHT"] as? String ?? "0"
let apch_ifr = value?["APCH_IFR"] as? String ?? "0"*/
self.thisIntDayLdg = Int(this_flight_ldg_day) ?? 0
/*self.intLdgNight = Int(ldg_night) ?? 0
self.intApchIfr = Int(apch_ifr) ?? 0*/
self.thisStringDayLdg = this_flight_ldg_day
/*self.currentStringLdgNight = ldg_night
self.currentStringApchIfr = apch_ifr*/
print("thisFlightInfo : IntDay : \(self.thisIntDayLdg) & StringDay : \(self.thisStringDayLdg)")
}
}
print("Calcul : \(self.newIntDayLdg) = \(self.oldIntDayLdg) + \(self.thisIntDayLdg)")
newIntDayLdg = oldIntDayLdg - thisIntDayLdg
print("int result : \(self.newIntDayLdg)")
newStringDayLdg = String(newIntDayLdg) ?? "00"
print("String result : \(self.newStringDayLdg)")
ref.child("Experience").child(userID!).updateChildValues(["LDG_DAY": self.newStringDayLdg//,
/*"LDG_NIGHT": self.currentStringLdgNight,
"APCH_IFR": self.currentStringApchIfr*/])
ref.child("flights").child(userID!).child(datas[indexPath.row].AutoId).removeValue()
self.tableView.reloadData()
}else{
// si non connecté alors DECONNEXION !!!!
fatalError("⛔️ error ...")
}
datas.remove(at: indexPath.row)
tableView.reloadData()
}
}
但是这个每次都给我发0,而不是物超所值...
let ldg_day = value?["LDG_DAY"] as? String ?? "0"
给我0
和
let this_flight_ldg_day = value?["LDG_DAY"] as? String ?? "0"
也给我0
此外,通过我的所有打印,我检测到代码首先打印:
print("Calcul : \(self.newIntDayLdg) = \(self.oldIntDayLdg) + \(self.thisIntDayLdg)")
然后
print("String result : \(self.newStringDayLdg)")
并且只有在两次打印之后:
print("getUserInfo : IntDay : \(self.oldIntDayLdg) & StringDay : \(self.oldStringDayLdg)")
&
print("thisFlightInfo : IntDay : \(self.thisIntDayLdg) & StringDay : \(self.thisStringDayLdg)")
问题出在哪里 ?
谢谢
解决方案
推荐阅读
- javascript - 在 Tampermonkey/Greasemonkey 中使用 Javascript 在 Facebook Messenger 网页版上禁用 Enter 提交文本
- swift - 如何在我的视图控制器上检测跨多个视图的触摸事件?
- python - 为什么它显示错误的数字?
- javascript - Javascript 类方法响应“不是函数”
- python - 蟒蛇硒。并行 if 循环
- hadoop - 如何计算 MapReduce 作业需要多少个映射器
- bash - 努力归档来自父目录和子目录的日志文件
- javascript - 反应:OnClick 无法设置未定义错误反应的属性“长度”
- python - 如何使用 matplotlib 解决 TypeError 异常?
- csv - JMeter 中 CSV 数据集配置的替代方法是什么?