How to make an infinite UITableView?

I have some options in a UITableView and you want the user to be able to scroll forever. When the end is reached, I want to add a beginning so that the user can continue to scroll.

How can I do it?

+1
source share
2 answers

In tableView:numberOfRowsInSection: return some huge amount and act accordingly in tableView:cellForRowAtIndexPath: returning the same cells again and again.

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

Is it a coincidence that you use a table view for something that doesn't suit him? You might be better off using only UIScrollView and moving subviews as the user scrolls.

+3
source

I think the only problem is how to trick the numberOfRows: method. One possible solution is to return a large quantity, for example, 10 000 . Then you set the correct cellForRowAtIndexPath: to return based on your modulus data number. For example, if you have 100 data objects, you should get indexPath.row% 100

+2
source

All Articles