Load More data on Scroll Demand on CollectionView

后端 未结 3 2100
臣服心动
臣服心动 2020-12-29 14:52

I am implementing a feature on the collectionView where user scrolls the collectionView at the bottom (20 items) and it requests another set of data (20 more items) from the

3条回答
  •  猫巷女王i
    2020-12-29 15:20

    Swift 4.2

    When you call reloadData() inside CollectionView delegate method you will see blank cells. You need call it like this.

    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        if indexPath.row == collectionView.numberOfItems(inSection: indexPath.section) - 1 {
            updateNextSet()
        }
    }
    
    func updateNextSet(){
        print("On Completetion")
        //requests another set of data (20 more items) from the server.
        DispatchQueue.main.async(execute: collectionView.reloadData)
    }
    

提交回复
热议问题