Swift tableView Pagination

后端 未结 14 1407
长情又很酷
长情又很酷 2020-11-28 20:00

I have success working tableview with json parsing codes.But may have 1000 more item so need pagination when scrolling bottom side. I dont know how can i do this my codes un

14条回答
  •  醉酒成梦
    2020-11-28 20:44

    here is a sample code for collection view :

    var page = 0
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        print("page Num:\(page)")
    }
    
    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath){
         if arrImagesData.count-1 == indexPath.row && arrImagesData.count%10 == 0{
            getMoreImages(page)
         }
    }
    
    func getMoreImages(page:Int){ 
       //hit api
       if api_success == true {
           if self.page == 0 {
              self.arrImagesData.removeAll()
           }
       self.arrImagesData.appendContentsOf(api_data)
       self.collectionImages.reloadData()
       self.page = self.page + 1
       }
    }
    

提交回复
热议问题