Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite Scroll on iOS with Swift

I'm an iOS newbie and I would like to know how to detect when the user scrolls and reaches the bottom of an UITableView so I can load new data into the table.

I would also like to know where such a method should be implemented (the tableview's class or the view controller in which this tableview exists) Cheers!

like image 832
Luca Boieru Avatar asked Sep 29 '14 17:09

Luca Boieru


2 Answers

You can use -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath to and check if the last cell will be shown in the TableView's data source.

like image 83
ansible Avatar answered Oct 12 '22 00:10

ansible


iOS' TableViewController takes care of that automatically. It asks its datasource only for the currently visible rows of the table (tableview.cellForRowAtIndexPath)

See the documentation for the UITableViewDatasource Protocol Reference

like image 28
zisoft Avatar answered Oct 11 '22 23:10

zisoft