问题
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!
回答1:
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.
回答2:
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
回答3:
If you've got a "known dataset" (as in, you don't need to make a network call to fetch new data), then like @zizoft said, it'll be handled automatically in tableview.cellForRowAtIndexPath
If, however, you've got an "unknown dataset", (as in, you'll need to pull down data from the internet), you'll need to do something a bit more interesting - @ansible's suggestion would be appropriate in that case.
来源:https://stackoverflow.com/questions/26105636/infinite-scroll-on-ios-with-swift