Showing cells in demands in UICollectionView with vertical infinite scroll

后端 未结 3 649
别跟我提以往
别跟我提以往 2020-12-14 04:34

I would like to know how to achieve using a UICollectionView the desired effect of loading in demand like in the Amazon app when you make a sea

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 05:23

    I am also working on infinity scroll on UICollectionView. Here is the function which you need.

    func scrollViewDidScroll(scrollView: UIScrollView) {
        let offsetY = scrollView.contentOffset.y
        let contentHeight = scrollView.contentSize.height
        if offsetY > contentHeight - scrollView.frame.size.height {
            println("this is end, see you in console")
        }
    }
    

    And you can write your code in if clause. reloadData() I think.

    // load data for collection view
    func loadGroundData(){
        AVCloud.callFunctionInBackground("GroundWaterFallList", withParameters: [:]) {
            (result: AnyObject!, error: NSError!) -> Void in
            if error == nil {
                NSLog("ground users count: \(result.count)")
                NSLog("\(result[0])")
                self.ground_water_fall_people = result as NSArray
                self.collectionView?.reloadData()
            }
        }
    }
    

    well, I am still working on it, hope this help. And hope someone can explain these two functions. collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) scrollViewDidScroll

提交回复
热议问题