hi是从firebase中获取数据并存储到自定义类中并显示在tableview中,当我显示tableview时它不显示为空,但是当我使用另一个数组数据进行调用时
class datapass {
var fullName : String?
var status : String?
var dateAndTimeofVisit :String?
var profilephot :String?
var uid :String?
var inviterUID: String?
init(fullname:String?,status:String?,dateAndTimeofVisit:String?,profilephot:String,uid:String?,inviterUID:String?) {
self.fullName = fullname
self.status = status
self.dateAndTimeofVisit = dateAndTimeofVisit
self.profilephot = profilephot
self.uid = uid
self.inviterUID = inviterUID
}
}
viewdidload内部
var datapassval = [datapass]()
HandedDataRef = Database.database().reference()
.child(Constants.FIREBASE_CHILD_VISITORS)
.child(Constants.FIREBASE_CHILD_PRE_APPROVED_VISITORS).child("-LHO1TuRZTKCZV5Mli13")
HandedDataRef?.observeSingleEvent(of: .value, with: {(snapshot) in
print("snapshot values",snapshot)
if snapshot.exists() {
let visitorData = snapshot.value as? [String: AnyObject]
print("visitordata",visitorData as Any)
let dateAndTimeOfVisit = visitorData?[VisitorListFBKeys.dateAndTimeOfVisit.key] as? String
let fullName = visitorData?[VisitorListFBKeys.fullName.key] as? String
let inviterUID = visitorData?[VisitorListFBKeys.inviterUID.key] as? String
let mobileNumber = visitorData?[VisitorListFBKeys.mobileNumber.key] as? String
let profilePhoto = visitorData?[VisitorListFBKeys.profilePhoto.key] as? String
let status = visitorData?[VisitorListFBKeys.status.key] as? String
let uid = visitorData?[VisitorListFBKeys.uid.key] as? String
self.datapassval.append(datapass.init(fullname: fullName, status: status , dateAndTimeofVisit: dateAndTimeOfVisit, profilephot: profilePhoto!, uid: uid, inviterUID: inviterUID))
}
})
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return datapassval.count //count getting 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! HandedThingsToGuestTableViewCell
let datamy = datapassval[indexPath.row]
print("datamy",datamy)
cell.lbl_VisiterName.text = datamy.fullName
}
它没有显示任何东西如何显示我犯错的自定义类数据
答案 0 :(得分:0)
您需要重新加载表格
self.datapassval.append(datapass.init(fullname: fullName, status: status , dateAndTimeofVisit: dateAndTimeOfVisit, profilephot: profilePhoto!, uid: uid, inviterUID: inviterUID))
self.tableView.reloadData()