Swift tableView Pagination

后端 未结 14 1378
长情又很酷
长情又很酷 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:45

    I've tried an approach with willDisplayCell. But it produces unwanted stops during scrolling which makes the user experience not good. I think a better way is to do it in scrollViewDidEndDecelerating delegate method. It calls when the scroll finishes and only then new data comes. User sees that there is new content and scroll again if he wants. I've taken the answer here but instead of scrollViewDidEndDragging I use scrollViewDidEndDecelerating. It looks just better in my case. Here is some code from my project.

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        guard scrollView == tableView,
            (scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height,
            !viewModel.isLastPeriodicsPage else { return }
    
        viewModel.paginatePeriodics(tableView.getLastIndexPath())
    }
    

提交回复
热议问题