我在这里有我的功能,应该拉动孩子的所有位置"启动"在我的数据库中。
import UIKit
import Firebase
import FirebaseDatabase
class SearchSelectVC: UIViewController, UIPickerViewDelegate , UIPickerViewDataSource{
@IBOutlet weak var locationPicker: UIPickerView!
@IBOutlet weak var datePicker: UIPickerView!
@IBOutlet weak var locationLB: UILabel!
@IBOutlet weak var dateLB: UILabel!
var locData: [String] = [String]()
var dateData : [String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
initPickers()
getloc(onCompletion: { (data) in
print(data)
self.locData = (data)
})
}
func getDate(onCompletion: @escaping ([String]) -> ()) {
var data : [String] = []
let selectedLoc = locationLB.text
var dateRef: DatabaseReference!
dateRef = Database.database().reference().child("launch").child((selectedLoc)!)
dateRef.observe(.value) { (snapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
data.append(key)
print("date = \(key)")
//print(data)
}
onCompletion(data)
}
}
func getLoc(onCompletion: @escaping ([String]) -> Void){
print("here3")
var data : [String] = []
var locRef: DatabaseReference!
locRef = Database.database().reference()
print("here4")
locRef.child("launch").observe(.value) { snapshot in
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
print(snap)
print(key)
data.append(key)
print("location = \(key)")
//print(data)
}
onCompletion(data)
}
}
func initPickers(){
locationPicker.delegate = self
locationPicker.dataSource = self
datePicker.delegate = self
datePicker.dataSource = self
}
}
没有"here"
语句被打印出来,也没有打印出密钥的快照或正在收集的数据。我不确定我的代码有什么问题。这是我database的照片
谢谢!