Jigar Tarsariya Jigar Tarsariya - 1 year ago 123
Swift Question

Call api at specific scrollpoint while scrolling table view

I have one tableview and displaying products within custom cell.

There are so many records so i am using pagination right now but i want to call api for pagination when scroll point match with tableview cell scroll point before last 3 rows remains to scroll.

In short, I want to call api before last 3 rows is remains to scroll in table.

If there is other way to do like this then it will be appreciate.

Thank you in advance.

Answer Source

You can use the UITableView delegate method willDisplayCell:ForRowIndexPath:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    let needToFetchNewData = indexPath.row + 3 == datasource.count

    if needToFetchNewData {

I'd like to consider also a variable isAlreadyDownloading since the user can still scroll while you're fetching new data and it'll generate more than once the same request

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download