The problem i'm facing is to add a bunch of images next to each other vertically and make the whole thing scrollable. The images are 768x768. I'm using UITableView for this.
First i've tried to do it simply by dequeueing a single cell in the following method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Since my device only fits one and a half of such images vertically - i got a lag every time a new image was about to be loaded.
So ... i thought i'd simply test things by caching all cells in an array on application load. So now in my method for retrieving a cell looks like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PhotoItemCellController *cell = [imgs objectAtIndex:[indexPath row]];
return cell;
}
Here's the weird thing: all of this is the same as loading the images dynamically whenever needed - there is still the same lag... But ... when i scroll through the entire table to the end of it - the table begins to work flawlessly (obviously some sort of caching occurs).
- Why does this happen?
- Could it be because i'm using an array of cells instead of "dequeueing" them from table?
- Could it be because the cells contain UIImageView? Maybe it does something the first time it's shown.
Also i notice a spike in RAM usage only when i scroll through the table, and there's virtually no consumption when i load all cells with their images in memory on app launch.
Any thoughts appreciated