[英]I want to display data from firebase in a tableView
首先我知道這個問題已被問到,但我嘗試過的所有解決方案都沒有用。 我想從我的firebase實時數據庫中獲取數據並將其放入tableView中。 我的數據庫設置如下:
Clubs-
Club1-
Name- Club1
date- 5/09/18
在每個tableView單元格中,我想查看我的俱樂部名稱,然后是日期。 我的代碼編譯得很好但不做任何事情。 我的TableViewControllers標題是“Cell”,但我在tableViewCell上沒有重用標識符。
//
// CoolTable.swift
//
//
// Created by AISD on 4/2/19.
//
import UIKit
import Firebase
import GoogleSignIn
var refa: DatabaseReference!
class CoolTable: UITableViewController{
var posts = [eventStruct]()
@IBOutlet var tableview: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
refa = Database.database().reference()
loadNews()
tableview.delegate = self
tableview.dataSource = self
}
struct eventStruct {
let name: String!
let date: String!
}
func loadNews() {
refa.child("Club").queryOrderedByKey().observe(.childAdded, with: { (snapshot) in
if let valueDictionary = snapshot.value as? [AnyHashable:String]
{
let name = valueDictionary["Name"]
let date = valueDictionary["date"]
self.posts.insert(eventStruct(name: name, date: date), at: 0)
self.tableview.reloadData()
}
})
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let label1 = cell.viewWithTag(1) as! UILabel
label1.text = posts[indexPath.row].name
let label2 = cell.viewWithTag(2) as! UILabel
label2.text = posts[indexPath.row].date
return cell
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.