Там у меня проблема с перезагрузкой tableView после добавления значения в массив.
Вот мой код
//
// HomeViewController.swift
// um
//
// Created by Arnav on 17/09/18.
// Copyright © 2018 Arnav. All rights reserved.
//
import UIKit
import Firebase
import FirebaseDatabase
import FirebaseAuth
class HomeTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var questions = [Question]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// var postQuestion = Question(questionName: "Hi", created_by: "Bye")
// print(postQuestion.name)
// print(postQuestion.created)
loadQuestions()
}
var list = ["milk", "bread"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.text = list[indexPath.row]
return cell
}
func loadQuestions() {
Database.database().reference().child("questionPosts").queryOrderedByKey().observe(.childAdded) { (snapshot) in
if let dict = snapshot.value as? NSDictionary {
//var questionName = dict["name"] as! String
//var created_by = dict["email"] as! String
let questionTitle = dict["name"] as? String ?? ""
let created_by = dict["email"] as? String ?? ""
self.list.append(questionTitle)
}
}
}
Этот код только что добавил новое значение вМассив списка и табличное представление отображают что из массива списка, но когда я добавляю что-то новое в массив списка и запускаю его на симуляторе, новое значение не