I want to choose and display the correct dataset from Firebase, based on the pickerView selection.
The main problem - the values of the UILabels are not changing. The second thing I would like to note, that the pickerView does not disappear after I click on one of the values in it.
import UIKit
import Firebase
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var priceView: UILabel!
@IBOutlet weak var dayView: UILabel!
@IBOutlet weak var monthView: UILabel!
@IBOutlet weak var personPicker: UITextField!
var ref: DatabaseReference?
var databaseHandle: DatabaseHandle?
var postData = [String]()
var person : String = "jack"
let people = ["jack", "jenny", "don"]
override func viewDidLoad() {
super.viewDidLoad()
let pickerView = UIPickerView()
personPicker.delegate = self
personPicker.inputView = pickerView
ref = Database.database().reference()
ref?.child("xf").child(person).child("price").observe(.value, with: { (snapshot) in
if let i = snapshot.value as? Double
self.priceView.text = "\(i)"
self.priceView.reloadInputViews()
}
})
ref?.child("xf").child(person).child("day").observe(.value, with: { (snapshot) in
if let i = snapshot.value as? String {
self.dayView.text = "\(i)"
self.dayView.reloadInputViews()
}
})
ref?.child("xf").child(person).child("month").observe(.value, with: { (snapshot) in
if let i = snapshot.value as? String {
self.monthView.text = "\(i)"
self.monthView.reloadInputViews()
}
})
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return people.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return people[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
personPicker.text = people[row]
person = people[row]
}
}
For the first issue, I tried adding the 'person = people[row]' but the values in the UILabes do not change
For the issue with the pickerView removal, I tried adding 'pickerView.isHidden = true', but it only removes the values, not the card
Xcode Version 12.3