사용자가 참여하고있는 채팅의 tableView를 생성하려고합니다. 나는 그들의 사이트에서 firebase 튜토리얼을보고 있었고 사용자가 아이를 만들고 그 아이에게 방의 이름을 추가하기위한 일부인 대화방 목록을 쉽게 얻을 수 있다고 말했다. 데이터베이스를 쿼리하는 Swift와 Firebase
그래서 내 구조는Users
UNIQUE KEY
nickname: "name"
rooms
name: true
Room
etc etc
같은 내 cellForRow에 내가
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
firebase.child("users").child(fUID).observeSingleEvent(of: .value, with: { snapshot in
for user in snapshot.children.allObjects as! [FIRDataSnapshot]{
self.names = (user.value?["participating"] as? String)!
}
})
cell.textLabel?.text = self.names
cell.detailTextLabel?.text = "test"
return cell
}
가 나는 오류가이 코드를 사용하고 보이는 I PO 이름을 빈 문자열
와 때누군가가 내가 무엇이 잘못되었고 어떻게 고칠 수 있는지 이해할 수 있습니까? 당신이
내가 코드를 입수했습니다 1
편집 부분적으로
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let ref = firebase.child("users").child(fUID).child("participating")
ref.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot.value)
var dict = [String: Bool]()
dict = snapshot.value as! Dictionary
for (key, _) in dict {
self.names = key
print(self.names)
}
self.rooms.append(self.names)
self.tableView.reloadData()
})
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.rooms.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = self.rooms[indexPath.row]
cell.detailTextLabel?.text = "test"
return cell
}
일을 주셔서 감사합니다 문제는 지금 거기 중포 기지에서 2 개 항목 ... 그리고 그것은 단지 하나를 보여주고 있다는 점이다 그 중
cellForRowAtIndexPath 외부의 전체 배열을 관찰합니다. 예 : viewDidAppear. 그런 다음 가져온 항목이 있으면 tableview를 다시로드하십시오. – DogCoffee
내 문제는 줄 self.names에 .... 나는 EXC_BAD_Instruction .... 오류가 발생합니다. – RubberDucky4444
당신이 만들고있는 firebase에 대한 호출이 콜백에 있습니다. 그래서 전체 설정이 잘못되었습니다. Firebase 호출을 위에서 설명한대로 위임 메소드 내로 이동하지 마십시오. – DogCoffee