私は数時間戦ってきましたが、2つのことを理解できないようです。Firebase Pagination - Swift 3
は、どのように私は私が「queryLimitedToLast」と「queryEndingAtValue」を使用していますし、今の私の記事がまったく表示されていません。「アイテム」の私の配列にそれらを追加する(最初の最新の投稿をすべて表示することができます。
私のそれは私の配列に数回の項目を追加した仕事をしていました。事前に
感謝。
ここに私のデシベルです それはアイテムを追加して働いていたとき
は、私はここでfirebaseすることは非常に新しい、私のコードだと、本当にちょうど私が私がここでやっているのか分からない認めるだろう。..
func downloadPostsFromFirebase(withValue: String) {
// 1 - Get a reference to the database
ref = FIRDatabase.database().reference(withPath: "items-for-sale")
var startKey = withValue
var count = GlobalConstants.FirebaseConstants.numerOfPostsPerPage
var query = ref.queryOrderedByKey()
if startKey != nil {
query = query.queryEnding(atValue: startKey)
count += 1
}
query.queryLimited(toLast: UInt(count)).observeSingleEvent(of: .value, with: { snapshot in
guard var children = snapshot.children.allObjects as? [FIRDataSnapshot] else {
// Handle error
return
}
if startKey != nil && !children.isEmpty {
// TODO - If the number of items in the array is equal to the number of items in the db now, then stop?
for child in snapshot.children {
// instance of ItemForSale, it's added to the array that contains the latest version of the data.
let itemForSaleSingle = ItemForSale(snapshot: child as! FIRDataSnapshot)
startKey = itemForSaleSingle.key
self.items.append(itemForSaleSingle)
print("Total items count is \(self.items.count)")
self.collectionView?.reloadData()
print("start key is \(startKey)")
}
}
})
}
私は以下の2つの回答をしました。投稿ごとに1つの質問に限定してください。ここ数週間で何度も何度も質問に答えてきたことは確かです。 –