gpt4 book ai didi

ios - 修复 Firebase Tableview 数据显示

转载 作者:行者123 更新时间:2023-11-29 05:44:50 24 4
gpt4 key购买 nike

我正在设置一个UITableView来在我的应用程序上显示数据库内容。不幸的是,该信息没有显示并且导致应用程序崩溃。

给出的错误是:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

enter image description here

    typealias ItemInfo = (Titulo: String, Description: String, Rating: String, photo: String, email: String, location: String, telefone: String, Linkdetalhes: String)

fileprivate var items: [ItemInfo]! = [( "Titulo","Description","Rating","photo","email","location","telefone", "Linkdetalhes")]


(UIApplication.shared.delegate as! AppDelegate).fireBaseRef.observe(.value, with: { snapshot in
let dictRoot = snapshot.value as? [String : AnyObject] ?? [:]
let dictAliances = dictRoot["Eventos"] as? [String: AnyObject] ?? [:]
for key in Array(dictAliances.keys) {
let alianceDic = dictAliances[key]
self.items.append(( alianceDic!["Title"] as! String, alianceDic!["photo"] as! String, alianceDic!["Description"] as! String, alianceDic!["Rating"] as! String, alianceDic!["email"] as! String, alianceDic!["location"] as! String, alianceDic!["telefone"] as! String, alianceDic!["Linkdetalhes"] as! String))

self.tableView?.reloadData()
}
print(dictAliances)
})

最佳答案

将代码替换为!字符串as?字符串。请参阅以下内容。忽略强制展开。字典中可能会发现空值或缺少键值。

self.items.append(( alianceDic!["Title"] as? String, alianceDic!["photo"] as? String, alianceDic!["Description"] as? String, alianceDic!["Rating"] as? String, alianceDic!["email"] as? String, alianceDic!["location"] as? String, alianceDic!["telefone"] as? String, alianceDic!["Linkdetalhes"] as? String))

关于ios - 修复 Firebase Tableview 数据显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56252129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com