I am using pagination for tableview, for that I have created spinner for tableview footer and calling that in scrollViewDidEndDragging but the spinner is not showing.. while pagination
code: with this code pagination is working but createSpinnerFooter is calling but not showing, why? where am i wrong. please guide me
var currentPageNumberVM: Int = 1
private func createSpinnerFooter() -> UIView {
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 100))
let spinner = UIActivityIndicatorView()
spinner.center = footerView.center
footerView.addSubview(spinner)
spinner.startAnimating()
return footerView
}
//and calling here
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
//Bottom Refresh
if scrollView == resultTableView{
if (((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height))
//if scrollView.contentOffset.y > (resultTableView.contentSize.height-100-scrollView.frame.size.height)
{
resultTableView.tableFooterView = createSpinnerFooter()
print("refresh called")
self.refresh()
}
}
}
@objc func refresh() {
if currentPageNumberVM <= searchData?.result?.jobs?.last_page ?? 1 {
jobSearchResultServiceCall()//service call
} else {
self.view.makeToast("No more data to show")
resultTableView.tableFooterView = nil
}
}
Edit: if i move resultTableView.tableFooterView = nil to else then issue is createSpinnerFooter is showing but once its load then cells not reloading i mean pagination is not working until i scroll again, why? where is the issue.

It's because of
resultTableView.tableFooterView = nilin yourrefresh()function that causes the spinner to be removed as soon as it was added.Here is how
scrollViewDidEndDraggingwith this line of coderesultTableView.tableFooterView = createSpinnerFooter()self.refresh()immediately which I believe calls an API in the backgroundrefreshyou are alsonilthe footer view before the API call has completedresultTableView.tableFooterView = nilAll this happens so fast that you don't see the spinner being added and removed.
This line
resultTableView.tableFooterView = nilshould go in yourelsecase and it should go in your API completion handler after the API has returned with a response or errorUpdate
You need to move
resultTableView.tableFooterView = nilto two places.One is in else block - OK, you have done this.
Another one is in the completion handler of your API call. It seems like your API call does not handle completion so I recommend you have a look at resource 1 and resource 2 to understand how to set up a completion handler for your API call.
Completion handler will let you know when you api call has completed and this is the second place you need to make the spinner to nil.
You need to change your
jobSearchResultServiceCall()to have a completion handler using the links above.Once this is done, you will have code that looks like this
Now your spinner gets dismissed if api call has completed or there are no more results to show