0
xcode의 Firebase 데이터베이스에서 선택을 시도하고 테이블에 결과를 표시하려고하지만 결과가 매우 이상합니다. 동일한 엔트리에서 for 루프를 실행하는 것과 같습니다. 아마 테이블 때문에. 특정 선택에 대한 Firebase 데이터베이스 쿼리
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let groceryItem = items[indexPath.row]
// Below is code to query users in Firebase to check if it is the current user.
let selection = ref.queryOrdered(byChild: "addedByUser").queryEqual(toValue : user.email)
selection.observeSingleEvent(of: .value, with:{ (snapshot: FIRDataSnapshot) in
if let value = snapshot.value as? [String: Any] {
print(value)
}
})
//End of code
//if user.email == groceryItem.addedByUser {
cell.textLabel?.text = groceryItem.name
cell.detailTextLabel?.text = groceryItem.addedByUser
// }
toggleCellCheckbox(cell, isCompleted: groceryItem.completed)
return cell
}
과 중포 기지입니다
{
"expense-items" : {
"20170509" : {
"addedByUser" : "[email protected]",
"amount" : 37,
"categoryType" : "Shopping",
"completed" : false,
"name" : "Dijon",
"paymentType" : "Cash"
},
"zambon" : {
"addedByUser" : "[email protected]",
"amount" : 13,
"categoryType" : "Shopping",
"completed" : false,
"name" : "zambon",
"paymentType" : "CreditCard"
},
"zouzouni" : {
"addedByUser" : "[email protected]",
"amount" : 24,
"categoryType" : "Kids",
"completed" : false,
"name" : "zouzouni",
"paymentType" : "Cash"
}
}
}
는 만 20,170,509은 로그인 한 사용자에서 내가 3 배 20,170,509 항목을 얻을. 테이블을 올바른 결과로 채우기 위해 선택 결과를 어떻게 계산합니까?
체크 아웃 한 적이 있습니까? https://stackoverflow.com/questions/40316200/firebase-queryequaltovalue-get-key-in-swift-2-3 – arvidurs
끝 부분에 다음을 추가하십시오. .queryLimited (toFirst : 1) – arvidurs
귀하의 질문에 JSON 트리 그림이 포함되어 있습니다. 실제 JSON을 텍스트로 바꾸십시오. [Firebase 데이터베이스 콘솔] (https://console.firebase.google.com/project/_/database/data/)에서 JSON 내보내기 링크를 클릭하면 쉽게 얻을 수 있습니다. . JSON을 텍스트로 사용하면 검색이 가능해 지므로 실제 데이터로 테스트하고이를 사용하여 쉽게 답변 할 수 있습니다. 일반적으로 할 일은 단지 좋은 일입니다. –