我正在使用Xcode和Firebas *。单击发布按钮时,它将数据保存到Firebase,并带您到UITableView
。但是由于某种原因,UITableViewCell
没有显示。我不知道为什么自定义单元格没有显示。为单元创建了自定义类,并将其链接到标识符。单元格上的内容是UILabel
。 UITableViewCell
为什么不显示Firebase中的数据?
import Foundation
import Firebase
class TableViewController: UIViewController,UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var OpenPost: UIButton!
let storiesRef = Database.database().reference().child("People").child("HomeFeed").child("Posts")
var stories = [Story]()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// download stories
storiesRef.observe(.value, with: { (snapshot) in
self.stories.removeAll()
for child in snapshot.children {
let childSnapshot = child as! DataSnapshot
let story = Story(snapshot: childSnapshot)
print(story)
self.stories.insert(story, at: 0)
}
self.tableView.reloadData()
})
}
override func viewDidLoad()
{
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return stories.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Story Cell", for: indexPath) as! StoryTableviewcell
let story = stories[indexPath.row]
cell.story = story
return cell
}
}