Swift 4从Firebase数据库检索数据 func retPost2(){ runNBPOST() ////////////////////////////////////1 var pic=[String]() var p=Post(用户ID:,postId:,postType:,描述:,地区:,城市:,地区:,街道:,区域:0,视图:,总价:0,图片:pic,街道宽度:0,属性类型:) //////用于检索所有邮件 打印(retNBPOST()) runNBPOST() 设nbpost=retNBPOST() 对于1..Int中的i{ DataService.instance.retPost2() //tableView.reloadData() 返回DataService.instance.arrpost.count } 覆盖函数视图将出现(uo动画:Bool){ super.viewwillbeen(true) } func表视图 (uTableView:UITableView,cellForRowAt indexPath:indexPath)->UITableViewCell{ 将cell=tableView.dequeueReusableCell(标识符为“PostCell”)设为!homecell 让post=DataService.instance.arrpost[indexPath.row] //让post=DataServiceTemp.instance.getPosts()[indexPath.row] cell.updateHomeView(post:post) //tableView.reloadData() 返回单元 }

Swift 4从Firebase数据库检索数据 func retPost2(){ runNBPOST() ////////////////////////////////////1 var pic=[String]() var p=Post(用户ID:,postId:,postType:,描述:,地区:,城市:,地区:,街道:,区域:0,视图:,总价:0,图片:pic,街道宽度:0,属性类型:) //////用于检索所有邮件 打印(retNBPOST()) runNBPOST() 设nbpost=retNBPOST() 对于1..Int中的i{ DataService.instance.retPost2() //tableView.reloadData() 返回DataService.instance.arrpost.count } 覆盖函数视图将出现(uo动画:Bool){ super.viewwillbeen(true) } func表视图 (uTableView:UITableView,cellForRowAt indexPath:indexPath)->UITableViewCell{ 将cell=tableView.dequeueReusableCell(标识符为“PostCell”)设为!homecell 让post=DataService.instance.arrpost[indexPath.row] //让post=DataServiceTemp.instance.getPosts()[indexPath.row] cell.updateHomeView(post:post) //tableView.reloadData() 返回单元 },swift,firebase,firebase-realtime-database,swift4,Swift,Firebase,Firebase Realtime Database,Swift4,我的IOS应用程序有问题。我正在使用Firebase保存和检索数据。所有连接都很好,检索到的数据很好,有时甚至不完整。 我的问题是,当我运行应用程序时,视图、标签、图片等首先显示为空,而这个组件应该显示从firebase检索到的数据。我不知道问题出在哪里。是时间还是其他原因?所以主要问题是在完全检索数据之前组件显示为空。我想强制应用程序不显示为空开始时为空,但显示包含数据的组件 我已经使用了google的所有方法 使用UIActivityIndicator将鼠标悬停在主VC上方,直到Fireb

我的IOS应用程序有问题。我正在使用Firebase保存和检索数据。所有连接都很好,检索到的数据很好,有时甚至不完整。
我的问题是,当我运行应用程序时,视图、标签、图片等首先显示为空,而这个组件应该显示从firebase检索到的数据。我不知道问题出在哪里。是时间还是其他原因?所以主要问题是在完全检索数据之前组件显示为空。我想强制应用程序不显示为空开始时为空,但显示包含数据的组件

我已经使用了google的所有方法

使用
UIActivityIndicator
将鼠标悬停在主VC上方,直到Firebase发出响应,然后将其移除。因此,主要问题是在完全检索数据之前,组件显示为空。”你的主要问题是你没有显示一行代码。没有人知道你在他们最疯狂的梦中是怎么做的。OP在Firebase有机会检索数据之前显示UI。应用程序“flow”应该让用户知道正在检索数据,然后在Firebase调用后在闭包内更新UI。你也可以e试图一次检索太多数据和/或处理数据的方式。但正如@ElTomato所述,我们确实无法提出更多建议,因为没有代码。请查看以下内容并
func retPost2(){
runNBPOST()
////////////////////////////////////1


var pic = [String]()
var p = Post(userId: "", postId: "", postType: "", description: "", Region: "", City: "", District: "", Street: "", Area: 0, View: "", TotalPrice: 0, Pictures: pic, StreetWidth: 0, PropertyType: "")






////// for to retrive all post




print(retNBPOST())
runNBPOST()
let nbpost = retNBPOST()


for i in 1..<nbpost{


    postiiD = "Post(\(i))"


    self._REF_BASE.child("Post").child(postiiD).observeSingleEvent(of: .value, with: { (snapshot) in
        let value = snapshot.value as? NSDictionary
        let UserID2 = value?["UserID"] as? String ?? ""
        p.userId = UserID2
    })





    self._REF_BASE.child("Post").child("\("Post(\(i))")/Adress").observeSingleEvent(of: .value, with: { (snapshot) in

        let value = snapshot.value as? NSDictionary
        let Region = value?["Region"] as? String ?? ""
        p.Region = Region
        let City = value?["City"] as? String ?? ""
        p.City = City
        print(p.City)
        let District = value?["District"] as? String ?? ""
        p.District = District
        let Street = value?["Street"] as? String ?? ""
        p.Street = Street
        let AdditionalNumber = value?["AdditionalNumber"] as? String ?? ""
        p.AdditionalNumber = AdditionalNumber
        let PostalCode = value?["PostalCode"] as? String ?? ""
        p.PostalCode = PostalCode
        let BuldingNo = value?["BuldingNo"] as? String ?? ""
        p.BuldingNo = BuldingNo


    })

    self._REF_BASE.child("Post").child("\(postiiD)/PostInfo").observeSingleEvent(of: .value, with: { (snapshot) in
        let value = snapshot.value as? NSDictionary
        let postType = value?["PostType"] as? String ?? ""
        p.postType = postType
        print(p.postType)
        let DateOfpost = value?["DateOfpost"] as? String ?? ""
        p.dateOfpost = DateOfpost
        let EndDateOfPost = value?["EndDateOfPost"] as? String ?? ""
        p.endDateOfPost = EndDateOfPost
        let NbOfShare = value?["NbOfShare"] as? String ?? ""
        p.nbOfShare = Int(NbOfShare)!
        let NbOfViews = value?["NbOfViews"] as? String ?? ""
        p.nbOfViews = Int(NbOfViews)!
        let LastUpdate = value?["LastUpdate"] as? String ?? ""
        p.lastUpdate = LastUpdate
        let Description = value?["Description"] as? String ?? ""
        p.description = Description
        let Publisher = value?["Publisher"] as? String ?? ""
        p.publisher = Publisher
        let ContactTime = value?["ContactTime"] as? String ?? ""
        p.contactTime = ContactTime
        let Payment = value?["Payment"] as? String ?? ""
        p.payment = Payment
        let TotalPrice = value?["TotalPrice"] as? String ?? ""
        p.TotalPrice = Double(TotalPrice)!
        let NearBy = value?["NearBy"] as? String ?? ""
        p.NearBy = NearBy
        let StreetWidth = value?["StreetWidth"] as? String ?? ""
        p.StreetWidth = Double(StreetWidth)!
        //  let Discount = value?["Discount"] as? String ?? ""
        // p.Discount =


    })



    self._REF_BASE.child("Post").child("\(postiiD)/Property").observeSingleEvent(of: .value, with: { (snapshot) in
        let value = snapshot.value as? NSDictionary
        let Area = value?["Area"] as? String ?? ""
        p.Area = Double(Area)!
        print(p.Area)
        let View = value?["View"] as? String ?? ""
        p.View = View
        let FamilyOrSingle = value?["FamilyOrSingle"] as? String ?? ""
        p.FamilyOrSingle = FamilyOrSingle
        let Level = value?["Level"] as? String ?? ""
        p.Level = Int(Level)!
        let HouseAge = value?["HouseAge"] as? String ?? ""
        p.HouseAge = Int(HouseAge)!
        let LandType = value?["LandType"] as? String ?? ""
        p.LandType = LandType
        let MeterPrice = value?["MeterPrice"] as? String ?? ""
        p.MeterPrice = Double(MeterPrice)!
        let NbRoom = value?["NbRoom"] as? String ?? ""
        p.NbRoom = Int(NbRoom)!

        let NbGuestroom = value?["NbGuestroom"] as? String ?? ""
        p.NbGuestroom = Int(NbGuestroom)!
        let NbBathroom = value?["NbBathroom"] as? String ?? ""
        p.NbBathroom = Int(NbBathroom)!
        let NbBedroom = value?["NbBedroom"] as? String ?? ""
        p.NbBedroom = Int(NbBedroom)!
        let NbLivingroom = value?["NbLivingroom"] as? String ?? ""
        p.NbLivingroom = Int(NbLivingroom)!
        let NbKitchen = value?["NbKitchen"] as? String ?? ""
        p.NbKitchen = Int(NbKitchen)!
        let PropertyType = value?["PropertyType"] as? String ?? ""
        p.PropertyType = PropertyType
        let NbApartment = value?["NbApartment"] as? String ?? ""
        p.NbApartment = Int(NbApartment)!


    })


    // complet
    self._REF_BASE.child("Post").child("\(postiiD)/Amenities").observeSingleEvent(of: .value, with: { (snapshot) in
        let value = snapshot.value as? NSDictionary
        let LiftAvailability = value?["LiftAvailability"] as? String ?? ""
        let KitchenAvailability = value?["KitchenAvailability"] as? String ?? ""
        let FurnitureAvailability = value?["FurnitureAvailability"] as? String ?? ""
        let CarageAvailability = value?["CarageAvailability"] as? String ?? ""
        let SwimmingPoolAvailability = value?["SwimmingPoolAvailability"] as? String ?? ""
        let ParkingAvailability = value?["ParkingAvailability"] as? String
        let FiberOpticAvailability = value?["FiberOpticAvailability"] as? String
        let FireplaceAvailability = value?["FireplaceAvailability"] as? String
        let DiningroomAvailability = value?["DiningroomAvailability"] as? String
        let LaundryAvailability = value?["LaundryAvailability"] as? String
        let CentralAirAvailability = value?["CentralAirAvailability"] as? String
        let BalconyAvailability = value?["BalconyAvailability"] as? String
        let MaidRoomAvailability = value?["MaidRoomAvailability"] as? String
        let DriverRoomAvailability = value?["DriverRoomAvailability"] as? String
        let InternalStairAvailability = value?["InternalStairAvailability"] as? String
        let BasementAvailability = value?["BasementAvailability"] as? String
    })


    arrpost.append(p)


}


}


func updateHomeView(post : Post){

    totalPriceLb.text = "\(String(post.TotalPrice)) SR"
    areaLb.text = String(post.Area)
    AddressLb.text = "\(post.City) \(post.District) \(post.Street)"
    imageName.image = UIImage(named: "HomePic.jpg")

    if post.PropertyType == "Home" {
        bathLb.text = String(post.NbBathroom)
        BedLb.text = String(post.NbBedroom)
        imageName.image = UIImage(named: "HomePic.jpg")
    }else if post.PropertyType == "Apartment" {
        bathLb.text = String(post.NbBathroom)
        BedLb.text = String(post.NbBedroom)
        imageName.image = UIImage(named: "ApartPic.jpg")
    }else if post.PropertyType == "Land"{
        bathLb.isHidden = true
        BedLb.isHidden = true
        imageName.image = UIImage(named: "LandPic.jpg")
    }




}





func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {



    DataService.instance.retPost2()
  // tableView.reloadData()


  return DataService.instance.arrpost.count

}
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)



}

func tableView
    (_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {



    let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as! homecell

    let post = DataService.instance.arrpost[indexPath.row]
 //  let post = DataServiceTemp.instance.getPosts()[indexPath.row]
    cell.updateHomeView(post: post)

  // tableView.reloadData()

    return cell


}