2017-09-20 1 views
1

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) 
} 
+0

一つの方法は、あなたがデータをフェッチするために 'queryLimit'を使用することもでき得るよう

私たちは、私たちのカーソルの前/後の画像を取得し、クエリを制限するために、最初の時間をqueryStartingAtValuequeryEndingAtValueのいずれかを使用することができますクエリの制限を '10'と設定し、次に2回目に' 20'を設定するなどします – 3stud1ant3

答えて

0

であるあなたがページネーションを探しているように思える - 私はいつも私のために働く方法を持っています。

最初の要求では、クエリのページ数を20などに制限する必要があります。また、タイムスタンプやスコアなどの増分可能なインデックスでクエリを並べ替える必要があります。このキーは、画像の次のセットを取得するページングカーソルとして機能します。

イメージアレイ内の最後のオブジェクトのインクリメンタルインデックス値を取得することで、これを行うことができます。この例では、インクリメンタルインデックスとしてタイムスタンプを使用します。

セルが画面に表示されるときに呼び出されるUITableViewDelegateメソッドがあります。このメソッドを使用して、20番目のセルに到達したときを検出し、カーソルを使用して次のイメージのバッチをフェッチすることができます。我々は唯一の20

関連する問題