EmptyStack
EmptyStack

Reputation: 51374

UITableView with UIImageViews showing large UIImages - Scrolling Performance

I have a UITableView, with each cell containing 4 UIImageView s. I am loading the images asynchronously (using a third party UIImageView extension for asynchronous loading). And also doing the caching. So the table view scrolls freely. But I feel the lag in scrolling when I assign the images to UIImageView.

UIImage *image = [UIImage imageWithContentsOfFile:imageFileURL];
// Scroll is very smooth if I comment out the below line
imageView.image = image;

If I comment out the last line in above code, then the scrolling is faster. The scroll lags when I enable this line. So I need to find a way to assign image to image views without disturbing the scrolling.

One important thing to notice in my app is that, the images are large images, for example, they are above 500x500 px. I am not able to work on the image sizes, as they are coming from server and I don't have any control over it.

My only option is to find out the way to assign large images to the image views without blocking the UI interaction.

I want the scroll to work like Fancy app. I have seen Fancy app, where the scrolling is really smooth and there is not even a bit of a lag.

Is there any optimization tricks that I should follow?

Thanks everyone!

Upvotes: 1

Views: 544

Answers (2)

Alex Terente
Alex Terente

Reputation: 12036

  1. Create your custom cell. Minimise the use of transparency, and you can also draw your self all the content of the cell without using UIImageViews and UILables objects, this will produce a very fast scroll even on a 3g device.
  2. Cache all images in one array and in cell for row only read them.
  3. You can resize the images to the actual drawing size before adding them to the source array.
  4. Avoid objects allocation and deallocation in cell for row or in any other method used while scrolling. The object allocation is expensive.
  5. If you download them async while scrolling try not to create a new thread for each image. You can have one or more worker threads.

Upvotes: 2

iEinstein
iEinstein

Reputation: 2100

Please find the link i think it is very helpful for you here and here. I think the problem of this question is same as the problem in link. If not then let me know.

Upvotes: 0

Related Questions