I have around 5,000 objects which I'd like to place into a UITableView
. I'm currently doing this via a mechanism that plucks the first 50 from the array they're stored in, copies those to another array, then loads that array into the tableView. I then use willDisplayCell:forRowAtIndexPath
to automatically load in the next 50 when the table reaches the penultimate cell. It does this by just keeping track of where it stopped copying earlier, and copies the next 50, and repeats the process.
This poses a problem that I've not solved yet: I should be unloading the first 50 when I load in, say, the third 50. So, we go from 0 to 50, then 50 to 100, then 100 to 150, and at that point, I need to remove 0-50. If the user scrolls back to the top of the list, it would need to load in the previous 50 again. Basically, the table would have no more than 150 entries at any one time, so 0-150, or 50-200, or 100-250, or 150-300, etc.
What I'm wondering is whether this is the best way to approach something like this. There isn't a problem with slowdown when the user scrolls to the end of the table, but I'm wondering whether something like asynchronous loading of the data would be better? I'm really new to multi-threading but if it's going to be a simpler method, I'd love to give it a try.
Hopefully this being a more opinion-based question won't be an issue, I realise there's probably not one set answer, but in case I get "not a real question", my question is: is the approach described above the most efficient and effective way to gradually load a large amount of data into a UITableView
, and is there a more conventional means of achieving a similar effect via multi-threading, lazy loading, or other techniques?
EDIT: I'd also point out that the vast majority of the cells do not contain images, they're just a couple of UILabel
instances.