我正在尝试使用具有3个字段的UIPickerView查询Firestore,但未显示任何内容。如果我注释掉两个字段并运行查询,我会得到结果。任何想法,我想念或做错了什么。请帮忙。
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if hospNameField.isFirstResponder {
let itemselected = hospt[row]
hospNameField.text = itemselected
} else if teamNameField.isFirstResponder {
let itemselected = team[row]
teamNameField.text = itemselected
} else if mdNameField.isFirstResponder {
let itemselected = assignedmd[row]
mdNameField.text = itemselected
}
}
@IBAction func getData(_ sender: Any) {
if HOSP != (hospNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("hosp", isEqualTo: (hospNameField.text!))
} else if TEAM != (teamNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("team", isEqualTo: (teamNameField.text!))
} else if ASSIGNEDMD != (mdNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("assignedmd", isEqualTo: (mdNameField.text!))
query.getDocuments { (snapshot, error) in
if let err = error {
debugPrint("error getting data: \(err)")
} else {
for document in (snapshot?.documents)! {
print(document.data())
}
答案 0 :(得分:1)
我认为您缺少括号。如果运行查询,则仅执行第三个if语句。应关闭最后一个else if,然后运行查询。
尝试一下:
@IBAction func getData(_ sender: Any) {
if HOSP != (hospNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("hosp", isEqualTo: (hospNameField.text!))
} else if TEAM != (teamNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("team", isEqualTo: (teamNameField.text!))
} else if ASSIGNEDMD != (mdNameField.text!) {
query = Firestore.firestore().collection(PTLIST_REF).whereField("assignedmd", isEqualTo: (mdNameField.text!))
}
query.getDocuments { (snapshot, error) in
if let err = error {
debugPrint("error getting data: \(err)")
} else {
for document in (snapshot?.documents)! {
print(document.data())
}
}
}
}