CollectionView波涛汹涌的滚动

时间:2018-05-25 09:18:23

标签: asynchronous uicollectionview

在这里和那里进行了研究,但可能遗漏了一些东西。 使用SDWeb进行缓存。

我的目标是在我到达第10个时预先装载20个细胞:

override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell,
                          forItemAt indexPath: IndexPath) {
    if indexPath.item == (loadingPostCount - 10) {loadFeed()}
}

我的loadFeed()调用其他方法来执行脏工作:

DispatchQueue.global(qos: .userInitiated).async  {
    self.loadingPostCount = self.posts.count + 20
    query?.queryLimited(toLast: 21).observeSingleEvent(of: .value, with: { snapshot in
        if let reversed = snapshot.children.allObjects as? [DataSnapshot], !reversed.isEmpty {
            self.nextEntry = reversed[0].key
            self.collectionView?.performBatchUpdates({
                for index in stride(from: reversed.count - 1, through: 1, by: -1) {
                    self.loadItem(reversed[index])
                }
            }, completion: nil)
        }
    })        
}

一旦我到达第10个单元格,滚动被阻止,所以我认为我在异步线程上做错了。有什么建议吗?

感谢。

0 个答案:

没有答案
相关问题