Ios Firebase数据未在xcode的tableview中显示
我一直在尝试从firebase实时数据库中检索配置文件数据,并将其显示在表视图中,到目前为止,当我运行模拟器时,TabeView显示为空白并失败:显示错误0:50[50]。我对斯威夫特很陌生,不知道问题出在哪里 这是我的密码:Ios Firebase数据未在xcode的tableview中显示,ios,swift,firebase,firebase-realtime-database,tableview,Ios,Swift,Firebase,Firebase Realtime Database,Tableview,我一直在尝试从firebase实时数据库中检索配置文件数据,并将其显示在表视图中,到目前为止,当我运行模拟器时,TabeView显示为空白并失败:显示错误0:50[50]。我对斯威夫特很陌生,不知道问题出在哪里 这是我的密码: import UIKit import FirebaseDatabase import FirebaseStorage import FirebaseAuth class userViewController: UIViewController, UITableView
import UIKit
import FirebaseDatabase
import FirebaseStorage
import FirebaseAuth
class userViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profileData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "firstName_cell",
for: indexPath)
self.tableView.reloadData()
cell.textLabel?.text = self.profileData[indexPath.item]
return cell
}
var profileData = [String]()
let storageRef = Storage.storage().reference()
var databaseRef = Database.database().reference()
var ref: DatabaseReference?
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
//let userID = Auth.auth().currentUser?.uid
ref?.child("users").observeSingleEvent( of: .childAdded, with: { (snapshot) in
let profile = snapshot.value as? String
if let actualProfile = profile{
self.profileData.append(actualProfile)
print(self.profileData)
self.tableView.reloadData()
}
}) { (error) in
print(error.localizedDescription)
}
}
}
不要在
cellForRow
方法中添加reloadData()
。。。。它将变成无限循环。。因此,从cellForRow
方法中删除self.tableView.reloadData()
,在重新加载tableView
时尝试重新加载它
您不应该在
tableView(uu:cellForRowAt:)
方法中调用tableView.reloadData()
,或者从同一UITableView
调用的任何其他UITableViewDataSource方法。为了更加清晰,在重新加载数据()时,会多次调用cellForRow来设置每个单元格好的,我已经做了,但是仍然没有显示任何数据。我确保数据库规则设置为true。这是输出:“应用程序委派不符合UIApplicationLegate协议。没有要激活的挂起快照。[Graphics]UIColor使用远超出预期范围的组件值创建。在要调试的UIColorBreakForOutOfRangeColorComponents上设置断点。此消息将只记录一次。是。。您需要设置tableviewprofileData的委托和数据源为空,但self.profileData.append(actualProfile)应该将firebase中的数据添加到它,但它没有追加?好的,我已经这样做了,但仍然没有显示任何数据。我确保数据库规则设置为true。这是输出:“应用程序委派不符合UIApplicationLegate协议。没有要激活的挂起快照。[Graphics]UIColor使用远超出预期范围的组件值创建。在要调试的UIColorBreakForOutOfRangeColorComponents上设置断点。此消息将只记录一次。