0
@IBAction func one_2(sender: AnyObject) {
if un_1.textColor == UIColor.blueColor() {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
self.ref.child("IssueLikes").child("Abortion").child("Downvotes").setValue(Int(aaDownvotes)! - 1)
}
})
aab = false
un_1.text = String(Int(un_1.text!)!-1)
un_2.text = String(Int(un_2.text!)!+1)
un_1.textColor = UIColor.whiteColor()
un_2.textColor = UIColor.blueColor()
aac = true
} else {
print("AAC")
}
} else if un_1.textColor == UIColor.whiteColor() {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
}
})
aab = false
un_2.textColor = UIColor.blueColor()
un_2.text = String(Int(un_2.text!)!+1)
aac = true
} else {
print("AAC")
}
} else {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
}
})
aab = false
un_1.textColor = UIColor.whiteColor()
un_2.textColor = UIColor.whiteColor()
un_2.text = String(Int(un_2.text!)!+1)
un_2.textColor = UIColor.blueColor()
aac = true
} else {
print("AAC")
}
}
}
從您的代碼中可以看到,我試圖在單擊按鈕時使用新值更新Firebase。然而,發生的情況是,當我點擊這些按鈕時,數據庫中的Firebase值變得瘋狂,每毫秒從1變爲0。使用Firebase Swift檢索數據錯誤
我檢查了我的代碼多次,只是找不到任何錯誤。任何幫助是極大的讚賞。
啊,這有助於immensly。關於這些神祕的標識符名稱,它是一個很大的應用程序,如果你說出整件事情,它實際上是一種有組織的方式。非常感謝。 –