Swift tableView Pagination

后端 未结 14 1247
长情又很酷
长情又很酷 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:56
    //It works fine 
    func getPageCount(TotalCount : Int) -> Int{
        var num = TotalCount
        let reminder = num % 50
        print(reminder)
        if reminder != 0{
            num = TotalCount/50
            num = num + 1
    
        }else{
            num = TotalCount/50
        }
        return num
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let TotalPage =  self.getPageCount(TotalCount: Int(Datacount)!)
        let lastItem = self.mainArr.count - 1
        if indexPath.row == lastItem {
            print("IndexRow\(indexPath.row)")
            if self.page < TotalPage-1 {
                self.view_Loader.isHidden = false
                self.view_LoaderHeight.constant = 50
            self.page += 1
            self.YourAPI()
            }
        }
    }`
    
    0 讨论(0)
  • 2020-11-28 20:57

    This is now a little bit easier with the addition of a new protocol in iOS10: UITableViewDataSourcePrefetching

    https://developer.apple.com/documentation/uikit/uitableviewdatasourceprefetching

    0 讨论(0)
提交回复
热议问题