Swift 尝试从Firebase检索数据时未调用tableView(tableView:UITableView,cellForRowAt indexPath:indexPath)函数
我是新手,所以请温柔一点 我正在设计一个从firebase检索对象并在firebase中显示它们的应用程序 我在这里配置firebase:Swift 尝试从Firebase检索数据时未调用tableView(tableView:UITableView,cellForRowAt indexPath:indexPath)函数,swift,uitableview,firebase,firebase-realtime-database,Swift,Uitableview,Firebase,Firebase Realtime Database,我是新手,所以请温柔一点 我正在设计一个从firebase检索对象并在firebase中显示它们的应用程序 我在这里配置firebase: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { FIRApp.configure() FIRDataba
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
// Override point for customization after application launch.
return true
}
然而,我发现当我运行应用程序时,我只会看到一个空白的白色屏幕。经过一些调试后,我意识到这是因为无法访问TableView(cellForRowAt indexPath:indexPath)代码块:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let BUCSItem = items[indexPath.row]
cell.textLabel?.text = BUCSItem.name
print("should show bucs")
return cell
}
我有其他必需的tableView方法:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
以下是我的viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let ref = FIRDatabase.database().reference(withPath: "BUCS-items")
tableView.allowsMultipleSelectionDuringEditing = false
ref.queryOrdered(byChild: "BUCSgoals").observe(.value, with: { snapshot in
var newItems: [BUCSItem] = []
for child in snapshot.children {
if let snapshot = child as? FIRDataSnapshot,
let BUCSItem = BUCSItem(snapshot: snapshot) {
newItems.append(BUCSItem)
}
}
self.items = newItems
self.tableView.reloadData()
})
}
但奇怪的是。当我断开与互联网的连接时,它工作得非常好,并且这些项目按照它们的本意出现在表中。只有当连接到internet时,它们才会显示
以下是断开连接时的情况:
连接时,名称相同,但名称不显示在表中
任何帮助都将不胜感激 我认为这是一个快速更新
ref.queryOrdered(byChild: "BUCSgoals").observe(.value
到
ref.queryOrdered(byChild: "BUCSgoals").observeSingleEvent(.value