【发布时间】:2017-02-23 16:55:55
【问题描述】:
我的视图控制器的图像:
这是我的代码
class AddViewController: UIViewController {
@IBOutlet weak var questionField: UITextField!
@IBOutlet weak var correctAnswer: UITextField!
@IBOutlet weak var optionA: UITextField!
@IBOutlet weak var optionB: UITextField!
var ref: FIRDatabaseReference?
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboard()
}
@IBAction func createQuestion(_ sender: Any) {
ref = FIRDatabase.database().reference(fromURL: "https://******.firebaseio.com/")
if questionField.text != "" && correctAnswer.text != "" && optionA.text != "" && optionB.text != ""
{
self.ref?.child("Questions").setValue(["Question": questionField.text, "CorrectAnswer": correctAnswer.text, "OptionA": optionA.text, "OptionB": optionB.text])
questionField.text = ""
correctAnswer.text = ""
optionA.text = ""
optionB.text = ""
}
else
{
print("Missing fields")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这是我在 Firebase JSON 中的目标:
我的代码正在运行,但它取代了 (ofc)。我的方法在保存问题方面是否正确,以便检索它会很容易?你能告诉我如何保存我的问题吗?
【问题讨论】:
标签: ios swift firebase swift3 firebase-realtime-database