John Farkerson John Farkerson - 1 year ago 50
Objective-C Question

Best practice when loading large database into UITableView

I'm creating a forum-type app where users ask questions and can answer each other's questions. The questions are stored in a UITableView by most recent, and there's also going to be a search functionality. Backend is coded in Node JS and uses SQLite. Currently, I am simply loading all the questions ever asked from the backend, and populating the UITableView with them. However, I realize that this will eventually become unrealistic, since this database will eventually have thousands of questions on it. How is this usually dealt with? Should I load all the questions to the client, then show them ten at a time or something? Or should I change the database to return ten at a time and load new ones every time I reach the bottom of the table view?

Answer Source

Simpler solution would be loading that data in batches. You can code in backend to send the data based on the data requested.

For example:

Request the data in such a format that has the following information:

 NSDictionary *parameters = @{ 
      @"customerId":@"this-is -not necessary",
      @"pageNumber":[NSNumber numberWithInt:pageOne],

So the server would send you the data based on your request. In this request you will be loading 25 results. When you keep on scrolling and reached the end of table view, you can request the next batch of details.

In this way you don't have to download all the data at once, also app responsiveness will be much faster by this approach.