Infinite Scroll on iOS with Swift

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 22:06:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!