[英]setValue method not updating to Firebase database
我正在嘗試測試將數據保存到Firebase數據庫中,但是遇到了一些問題。 這是用戶按下“提交”按鈕時需要的代碼:
var ref = FIRDatabase.database().reference()
var user = FIRAuth.auth()?.currentUser
@IBOutlet weak var titleEntry: UITextField!
@IBOutlet weak var townAndZip: UITextField!
@IBOutlet weak var pickPrice: UISegmentedControl!
@IBOutlet weak var pickDuration: UISegmentedControl!
@IBAction func tapBackground(sender: AnyObject) {
view.endEditing(true)
}
@IBAction func postTask(sender: AnyObject) {
if ((titleEntry.text?.isEmpty) != nil && (townAndZip.text?.isEmpty) != nil) {
var price:String = pickPrice.titleForSegmentAtIndex(pickPrice.selectedSegmentIndex)!
var duration:String = pickDuration.titleForSegmentAtIndex(pickDuration.selectedSegmentIndex)!
self.ref.setValue(["title": titleEntry.text!])
self.ref.child("tasks").child(user!.uid).setValue(["price": price])
self.ref.child("tasks").child(user!.uid).setValue(["duration": duration])
self.ref.child("tasks").child(user!.uid).setValue(["town_zip": townAndZip.text!])
self.performSegueWithIdentifier("postAdd", sender: self)
print("Posted!")
} else {
let alert = UIAlertController(title: "Error", message: "Please make sure you filled in everything.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Understood!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
無論我輸入什么內容,該應用程序都會執行segue,並且不會在我的Firebase數據庫中更新。 另外,如果我僅輸入其中一個字段的數據,它仍然會執行segue,並且不會顯示警報。 我以為這是Firebase本身的問題,但這很可能是我找不到的錯誤。 任何幫助將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.