UITableView + Firebase Database.

Hello. I am trying to make my TableView work with FirebaseDatabase.


So I've attached my code. I am completely confused what I'm doing wrong. I want that my TableView show keys(array) but it shows nothing.



import UIKit
import FirebaseDatabase
class SecondViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    var ref : DatabaseReference!
    var allWords = [String]()
   
   
    override func viewDidLoad() {
        super.viewDidLoad()
   
        /
    
        ref = Database.database().reference().child("addedWords")
        ref.observe(.value, with: { (DataSnapshot) in
           
            let newItems = DataSnapshot.value as! [String:Any]
            let keys = Array(newItems.keys)
           
           
            while(keys.count>self.allWords.count){
                var c = 0
                self.allWords.append(keys[c])
                c+=1
               
            print(self.allWords)
               
                }
           
            }
        )
       
    }
   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
  
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = allWords[indexPath.row]
        return cell
    }
   
   
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return allWords.count
       
       
    }
   
}
  

Replies

I do not know much about Firebase usage, but I cannot find any calls of `reload()` method for your table view. You may need it after all data loaded.