我有19个文本域要上传到firebase数据库。起初我写了这个ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue(["company name" : self.companyname.text, "category" : self.category.text, "email" : self.email.text, "phonenumber" : self.phonenumber.text, "hours" : self.hours.text, "logo" : self.logo.text, "yelplink" : self.yelplink.text, "totaloffer" : self.totaloffer.text, "cp0name" : self.cp0name.text, "cp0code" : self.cp0code.text, "cp0amount" : self.cp0amount.text, "cp0picture" : self.cp0picture.text, "cp1name" : self.cp1name.text, "cp1code" : self.cp1code.text, "cp1amount" : self.cp1amount.text, "cp1picture" : self.cp1picture.text])
和xcode陷入了索引。然后我将上传功能分成两部分:
ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue(["company name" : self.companyname.text, "category" : self.category.text, "email" : self.email.text, "phonenumber" : self.phonenumber.text, "hours" : self.hours.text, "logo" : self.logo.text, "yelplink" : self.yelplink.text, "totaloffer" : self.totaloffer.text])
ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue([""cp0name" : self.cp0name.text, "cp0code" : self.cp0code.text, "cp0amount" : self.cp0amount.text, cp0picture" : self.cp0picture.text, "cp1name" : self.cp1name.text, "cp1code" : self.cp1code.text, "cp1amount" : self.cp1amount.text, "cp1picture" : self.cp1picture.text])
只有第二个功能正在上传。我尝试添加一个延迟来查看互联网连接是否有问题但是,第二个功能仍然是唯一上传的功能。然后我尝试制作3个不同的功能,但现在没有一个上传。以下是我目前的代码,感谢任何帮助。
import UIKit
import Firebase
import FirebaseDatabase
let ref = Database.database().reference()
class admi: UIViewController, UITextFieldDelegate {
@IBOutlet weak var companyname: UITextF
ield!
@IBOutlet weak var category: UITextField!
@IBOutlet weak var email: UITextField!
@IBOutlet weak var phonenumber: UITextField!
@IBOutlet weak var hours: UITextField!
@IBOutlet weak var logo: UITextField!
@IBOutlet weak var yelplink: UITextField!
@IBOutlet weak var totaloffer: UITextField!
@IBOutlet weak var address0: UITextField!
@IBOutlet weak var childx: UITextField!
@IBOutlet weak var cp0name: UITextField!
@IBOutlet weak var cp0code: UITextField!
@IBOutlet weak var cp0amount: UITextField!
@IBOutlet weak var cp0picture: UITextField!
@IBOutlet weak var cp1name: UITextField!
@IBOutlet weak var cp1code: UITextField!
@IBOutlet weak var cp1amount: UITextField!
@IBOutlet weak var cp1picture: UITextField!
@IBOutlet weak var countyyryr: UITextField!
@IBAction func add(_ sender: Any) {
ref = Database.database().reference()
print(companyname.text!, category.text!, email.text!, phonenumber.text!, hours.text!, logo.text!)
print(yelplink.text!, totaloffer.text!, address0.text!, childx.text!, cp0name.text!, cp0code.text!, cp0amount.text!)
print(cp0picture.text!, cp1name.text!, cp1code.text!, cp1amount.text!, cp1picture.text!)
uplo()
sed()
dod()
delay(8) {
self.companyname.textColor = UIColor.green
self.category.textColor = UIColor.green
self.email.textColor = UIColor.green
self.phonenumber.textColor = UIColor.green
self.hours.textColor = UIColor.green
self.logo.textColor = UIColor.green
self.yelplink.textColor = UIColor.green
self.totaloffer.textColor = UIColor.green
self.address0.textColor = UIColor.green
self.childx.textColor = UIColor.green
self.cp0name.textColor = UIColor.green
self.cp0code.textColor = UIColor.green
self.cp0amount.textColor = UIColor.green
self.cp0picture.textColor = UIColor.green
self.cp1name.textColor = UIColor.green
self.cp1code.textColor = UIColor.green
self.cp1amount.textColor = UIColor.green
self.cp1picture.textColor = UIColor.green
}
delay(20){
self.companyname.textColor = UIColor.black
self.category.textColor = UIColor.black
self.email.textColor = UIColor.black
self.phonenumber.textColor = UIColor.black
self.hours.textColor = UIColor.black
self.logo.textColor = UIColor.black
self.yelplink.textColor = UIColor.black
self.totaloffer.textColor = UIColor.black
self.address0.textColor = UIColor.black
self.childx.textColor = UIColor.black
self.cp0name.textColor = UIColor.black
self.cp0code.textColor = UIColor.black
self.cp0amount.textColor = UIColor.black
self.cp0picture.textColor = UIColor.black
self.cp1name.textColor = UIColor.black
self.cp1code.textColor = UIColor.black
self.cp1amount.textColor = UIColor.black
self.cp1picture.textColor = UIColor.black
self.companyname.text = ""
self.category.text = ""
self.email.text = ""
self.phonenumber.text = ""
self.hours.text = ""
self.logo.text = ""
self.yelplink.text = ""
self.totaloffer.text = ""
self.address0.text = ""
self.childx.text = ""
self.cp0name.text = ""
self.cp0code.text = ""
self.cp0amount.text = ""
self.cp0picture.text = ""
self.cp1name.text = ""
self.cp1code.text = ""
self.cp1amount.text = ""
self.cp1picture.text = ""
}
}
override func viewDidLoad() {
super.viewDidLoad()
companyname.delegate = self
category.delegate = self
email.delegate = self
phonenumber.delegate = self
hours.delegate = self
logo.delegate = self
yelplink.delegate = self
totaloffer.delegate = self
address0.delegate = self
childx.delegate = self
cp0name.delegate = self
cp0code.delegate = self
cp0amount.delegate = self
cp0picture.delegate = self
cp1name.delegate = self
cp1code.delegate = self
cp1amount.delegate = self
cp1picture.delegate = self
countyyryr.delegate = self
}
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func uplo() {
print("reading one")
ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue(["company name" : self.companyname.text, "category" : self.category.text, "email" : self.email.text, "phonenumber" : self.phonenumber.text, "hours" : self.hours.text])
}
func sed() {
print("reading two")
ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue(["logo" : self.logo.text, "yelplink" : self.yelplink.text, "totaloffer" : self.totaloffer.text, "cp0name" : self.cp0name.text, "cp0code" : self.cp0code.text, "cp0amount" : self.cp0amount.text])
}
func dod() {
print("reading three")
ref.child("Coupons").child(self.countyyryr.text!).child(self.childx.text!).setValue(["cp0picture" : self.cp0picture.text, "cp1name" : self.cp1name.text, "cp1code" : self.cp1code.text, "cp1amount" : self.cp1amount.text, "cp1picture" : self.cp1picture.text])
}
答案 0 :(得分:0)
两个函数都在执行,但是您通过将值设置为其他值来覆盖路径的值。在设置路径的值后使用b
而不是.updateChildValues
,或者将更新组合到单个字典中并一次性设置值。
setValue
请参阅文档here。