您好,我已經嘗試了幾種方法,但基本上,我使用Python上傳的firebase數據庫中有一組數據。在Python中,我將所有內容添加到數組並將其上傳到數據庫。在斯威夫特我試圖找回這樣如何檢索來自Firebase的數據陣列
import UIKit
import Foundation
import Firebase
class CSGOView: UIViewController, UITableViewDelegate, UITableViewDataSource{
var teams: [String] = []
var times: [String] = []
@IBOutlet weak var tableViewTwo: UITableView!
let ref = FIRDatabase.database().reference(fromURL: "Took the url out it is the right url to the database im sure")
override func viewDidLoad() {
super.viewDidLoad()
getTeamsAndTimes()
}
func getTeamsAndTimes() {
//let userID = FIRAuth.auth()?.currentUser?.uid
ref.child("Teams").observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? [String: String] ?? [:]
for team in value {
print(team.key)
print(team.value)
}
// ...
}) { (error) in
print(error.localizedDescription)
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell? = nil
return cell!
}
}
該數據視圖時負載沒有被打印到控制檯不工作,雖然。我有方法在ViewDidLoad()中運行。
這裏的數據看起來像在火力數據庫(我得走了所以我會上傳它,當我回來)大概是喜歡
隊 0:「teamname」 1:「teamtwo的「
所以有團隊然後加號,它下降顯示一個字典與0作爲關鍵和」團隊名稱「作爲價值。如果有幫助,我沒有在鍵和值之前的隨機ID。我使用set方法而不是python中的push方法。 set方法上傳沒有id的數據。
事實證明,我無法上傳圖片,直到我有10個代表。
上面的鏈接將帶您到火力數據庫看起來像
不能真正幫助,如果我們不能看到的數據庫結構,使用* viewDidLoad *函數編輯您的問題。 – Dravidian
我更新了代碼以顯示整個班級,我還將數據庫圖片添加到該網站的底部。 @Dravidian –
您必須確保您的安全規則允許檢索數據 – Dravidian