Search code examples
iossqliteuitableviewcell

iOS UITableView filling when thousands of items


I have to fill a TableView with lots of items (20.000 items frol sqlite) but I know that I will overload it. Is there a way to load only the needed data when scolling ?

for example if I display 100 items when I scroll over 100 should I load 200 in the table or load only the items 101>200 ?

Also is it possible when returning the Cell content to fetch for EACH element in the embedded sqlite DB ?

Thanks


Solution

  • I have to fill a TableView with lots of items (20.000 items frol sqlite) but I know that I will overload it. Is there a way to load only the needed data when scrolling?

    UITableView is designed specifically to load only the cells that are visible. You don't so much "fill" a table as you make the data available to the table via the table's data source. As the table scrolls, it asks its data source for additional cells, and it re-uses the cells that are no longer visible. This minimizes memory usage and maximizes speed. You don't need to do anything to achieve this other than implement the necessary table view data source and delegate methods in your view controller (or some other object).

    Also is it possible when returning the Cell content to fetch for EACH element in the embedded sqlite DB ?

    Sure, you can do that. Just implement your -tableView:cellForRowAtIndexPath: method to make the appropriate SQLite query for the requested cell.