firebaseデータベースのノードを検索し、ノードからImage Urlの束を取り出し、ストレージにリンクされた画像をテーブルビューに表示するアプリがあります。一度にすべてをアップロードしないFirebase
問題は、何百もの画像である可能性のあるすべての画像を読み込むことです。データの過剰使用を防ぐために、一度に多くの作業を行うだけです。
スクロールしている人が最後に近づいてから、さらに10個アップロードすると理想的です。
ありがとうございます
func loadthumbimages()
{
let ref = Database.database().reference(withPath: "ImageLocations/\(myspoits!)/\(DatesTableViewController.passdata!)")
//observing the data changes
ref.observe(DataEventType.value, with: { (snapshot) in
//if the reference have some values
if snapshot.childrenCount > 0
{
//iterating through all the values
for mydata in snapshot.children.allObjects as! [DataSnapshot]
{
//getting values
let artistObject = mydata.value as? [String: AnyObject]
// This is the data of the node
let fileURL = artistObject?["fileURL"]
let thumbFileUrl = artistObject?["thumbFileUrl"]
let ImageName = artistObject?["ImageName"]
//print(artistObject)
self.myarray1.append("\(ImageName!)")
self.myarray2.append("\(thumbFileUrl!)")
self.myarray3.append("\(fileURL!)")
//print(thumbFileUrl!)
}
}
})
}
そして、ここに私のテーブルビューは
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myarray1.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MycustomCell", for: indexPath) as! MyimagecellTableViewCell
let urlString = "\(myarray2[indexPath.row])"
let url = URL(string: urlString)!
cell.myxcell.kf.setImage(with: url)
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("row: \(myarray2[indexPath.row])")
FetchdataViewController.fullimg = "\(myarray3[indexPath.row])"
FetchdataViewController.thumbimg = "\(myarray2[indexPath.row])"
self.performSegue(withIdentifier: "photofull", sender: self)
}
一つの方法は、あなたがデータをフェッチするために 'queryLimit'を使用することもでき得るよう
私たちは、私たちのカーソルの前/後の画像を取得し、クエリを制限するために、最初の時間を
queryStartingAtValue
かqueryEndingAtValue
のいずれかを使用することができますクエリの制限を '10'と設定し、次に2回目に' 20'を設定するなどします – 3stud1ant3