开发者

How to make an never ending UITableView?

开发者 https://www.devze.com 2023-01-17 11:16 出处:网络
I have some options in an UITableView and want that the user can scroll forever.开发者_JS百科 When the end is reached, I want to append the begginning so the user can continue to scroll.

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

How would I do that?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消