7

I implemented lazy image load for my UITableView using NSUrlConnection. This is all working very nicely. When I open my table, I automatically get the images when I wait for a second (on 3G). However, when I scroll, the table loads the new cell's, starts the NSURLConnections, but when the image is finished loading (in code), they do not get put into the view until the table actually stops scrolling..

The Youtube application is able to load the images into the table WHILE scrolling, I'd like to do this as well, any hints / pointers?

Stijn
  • 858
  • 2
  • 12
  • 21
  • I'd like to hear the answer for this too. BTW do you load each image on a separate thread? I get crashes if I scroll to fast, any ideas? – natanavra Jan 03 '10 at 19:41
  • I don't use threads (at least, not explicitly), I use NSURLConnection initWithRequest:delegate which works asynchronously.. – Stijn Jan 04 '10 at 11:21

2 Answers2

11

I just found my answer thanks to the 'Related' feature to the right.. Delayed UIImageView Rendering in UITableView

You have to start NSUrlConnection in a different run-loop, so that you receive data while the table is scrolling.

Thanks for the answers!

Community
  • 1
  • 1
Stijn
  • 858
  • 2
  • 12
  • 21
9

Take a look at the Apple example LazyTableImages.

If you request all the images for your table asynchronously, they will load as they arrive.

You'll notice some applications wait for scrollViewDidEndDragging and loadImagesForOnscreenRows to be truly lazy and only request images for rows the user is currently examining.

Hemang
  • 26,840
  • 19
  • 119
  • 186
Nuthatch
  • 3,597
  • 4
  • 24
  • 17
  • 2
    Actually that example works even worse then mine, because it only starts the thread to load the image when the table stops scrolling (not even when it comes into view). I'll take a look at how they do threading though.. My current app loads the rows as they come in, and stops them if you scroll past the image. The only problem is that they are not inserted into the table untill the table stops scrolling, and I don't exactly know why. I think even though my image loading occurs asynchronously, it's not really in a separate thread, hence it waits for the table to stop scrolling. – Stijn Jan 04 '10 at 11:17
  • That's true, but I found the sample to be really well done. I got it working really well with minor tweaks. – Echilon Dec 31 '11 at 15:16