使用 "IF" 和 UIPickerController 将数据上传到 Firebase

Uploading data to Firebase with "IF" and UIPickerController

我几周前开始编码,我正在尝试将数据加载到我的 Firebase.database 应用程序。但问题是,我希望数据 load/save 进入不同的 folders/names ("A" & "B") 在我的 firebase 数据库中,以便稍后我可以检索数据2 个不同的滚动视图,一个滚动视图仅显示 "A",一个仅显示 "B".

我的代码没有向我抛出错误,但由于某种原因它不会上传数据。我不知道为什么它不起作用。

非常感谢帮助。 感谢社区!!

代码来了!


/// 现在选择器

// 2 items for the picker.
var data = ["A", "B"]

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    // Column count: use one column.
    return 1
}

func pickerView(pickerView: UIPickerView,
                numberOfRowsInComponent component: Int) -> Int {

    // Row count: rows equals array length.
    return data.count
}

func pickerView(pickerView: UIPickerView,
                titleForRow row: Int,
                            forComponent component: Int) -> String? {

    // Return a string from the array for this row.
    return data[row]
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    true
}

//Here I try to Upload the image that I picked in UIPickerView

@IBAction func Upload(sender: UIButton){

    func simplePicker(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

        if component == 0 {

            func Upload(){
            _ = UIImage.self
            FIRDatabase.database().reference().childByAutoId().setValue("A")
            }}

        if component == 1 {

            func Upload(){
            _ = UIImage.self
            FIRDatabase.database().reference().childByAutoId().setValue("B")
            }}


    }

}

尝试:-

var valueToStore : String = "Placeholder"

@IBAction func Upload(sender: UIButton){

        FIRDatabase.database().reference().childByAutoId().setValue(valueToStore)
       //Storing the values the value you want to store ..
}


func simplePicker(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if component == 0 {
         valueToStore = "A" 
      }else if component == 1 {
         valueToStore = "B"}

  //Setting the value you want to store in a global variable..
}

终于找到办法了。我将 Post 适合我的解决方案。说不定对以后的人有帮助。

干杯,狮子座

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if row == 0 {FIRDatabase.database().reference().childByAutoId().setValue("A")}

    if row == 1 {FIRDatabase.database().reference().childByAutoId().setValue("B")}
}

P.s。问题是措辞。它不是组件。是 "rows" !