Leo Leo - 2 months ago 37
iOS Question

Uploading data to Firebase with "IF" and UIPickerController

I started coding a few weeks ago and I am trying to load data to my Firebase.database for my app. But the thing is, that I want the data to load/save into different folders/names ("A" & "B") in my database in firebase so that later i can retrieve the data on 2 different scroll views with one scroll view only showing "A" and one only showing "B".

My code is not throwing errors at me, but for some reason it won't upload data. i don't know why it is not working.

Help highly appreciated.
Thanks community !!

Code incoming !




/// Picker now

// 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")
}}


}

}

Leo Leo
Answer

finally I managed to find a way. I will Post the solution that worked for me. Maybe it will help someone in the future.

Cheers, Leo

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. The Problem was the phrasing. It is not components. It is "rows" !

Comments