【发布时间】:2020-10-26 13:38:29
【问题描述】:
将值附加到数组后,我在重新加载 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)
}
}
}
此代码只是向列表数组添加了一个新值,并且表格视图显示了列表数组中的内容,但是当我将新内容添加到列表数组并在模拟器上运行时,新值不会
【问题讨论】:
-
你只需要 wright tableviewname.reloadData()
-
@SagarBhut 检查定义:en.wiktionary.org/wiki/wright#Verb
标签: ios uitableview firebase-realtime-database swift4