Swift 4 UICollectionView detect end of scrolling

前端 未结 5 1548
野趣味
野趣味 2021-02-04 13:13

I have an Horizontal UICollectionView on my app and I want to load more data when the user reaches the end (or nearly to the end) of UICollectionView w

5条回答
  •  生来不讨喜
    2021-02-04 13:53

    Take one bool variable and one integer variable for page number like this:

    var isDataLoading = false
    var pageCount:Int = 1 // Pass this page number in your api
    

    in cellForItemAt method add below code:

    if !isDataLoading && indexPath.row == videoViewModel.count - 1 {
                isDataLoading = true
                pageCount += 1
    // add you api call code here with pageCount
            }
    

    once you get your data from api set isDataLoading bool to false like below:

    self.isDataLoading = false
    

提交回复
热议问题