How to make an never ending UITableView?

穿精又带淫゛_ 提交于 2019-12-24 17:48:47

问题


I have some options in an UITableView and want that the user can scroll forever. When the end is reached, I want to append the begginning so the user can continue to scroll.

How would I do that?


回答1:


In tableView:numberOfRowsInSection: return some huge number, and act accordingly in tableView:cellForRowAtIndexPath: by returning same cells over and over.

You can also have limited number of rows, and at the end show a different cell - containing a button for user which he can use to append new rows. When that button is clicked you simply call [tableView reloadData] and provide more rows in table's data source.

Aren't you by any chance misusing the table-view for something it doesn't fit that well ? Maybe you would be better off using just a UIScrollView and reposition subviews as user scrolls over.




回答2:


I think the only problem is how to trick in the method numberOfRows:. One possible solution is to return some big number here, for example, 10 000. Then, you set up a correct cellForRowAtIndexPath: to return based on your data's number modulo. For example, if you have 100 data entity, then you have to get the indexPath.row % 100



来源:https://stackoverflow.com/questions/3798188/how-to-make-an-never-ending-uitableview

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