0

I have a typical UITableView which displays a thumbnail image and some text. During tableView:cellForRowAtIndexPath: I start an async image download for each item in the list. The images are downloading, but not the way I want. For example, if I flick scroll the list, my download requests happen immediately, however, the connectionDidFinishLoading: message will not get fired, until the scrolling from the flick scroll comes to a complete stop. Basically, that results in the user seeing a bunch of empty images for a couple of seconds.

If you look at the app store app, for example, when you flick scroll one of the lists, the images begin displaying even when scrolling hasn't stopped. I'm assuming this is due to some kind of multi-threaded solution.

Can someone please provide me with an example of how I can acheive the desired results?

Thanks!

bpatrick100
  • 1,261
  • 1
  • 15
  • 23

3 Answers3

1

You probably need to do this :

[_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

Assuming _connection is your NSURLConnection.

Nyx0uf
  • 4,609
  • 1
  • 25
  • 26
  • I'm pretty sure this is the way to go, because this how we solved it. If it not's being displayed, just check your ScrollView delegate methods because maybe you're not assigning the image until the scroll is finished. – Yorxxx Feb 16 '11 at 08:04
  • The connectionDidFinishLoading: message in my image download object simply sends a delegate message to the view controller that requested the download, and the image is display in that delegate. The problem is, I never receieve the connectionDidFinishLoading: message while scrolling is happening, and yes the download request has already been sent. Even if I tap anywhere on the screen, and hold my finger down, no new images will draw until I let go. It is not because I have any logic checks in my view controller - it is because my view controller hasn't receive the notification. – bpatrick100 Feb 16 '11 at 14:25
  • It's as if the act of touches and scrolling is blocking the connectionDidFinishLoading: message. If you have this working, maybe you can post your code. – bpatrick100 Feb 16 '11 at 14:26
1

I ended up solving this myself, since no one on the planet could help me. If you would really like to know how to achieve this, I have described how to modify Apple's LazyTableImages sample project to achieve the desired effect here:

Question about Apple's LazyTableImages sample - Doesn't behave exactly like the app store

Community
  • 1
  • 1
bpatrick100
  • 1,261
  • 1
  • 15
  • 23
0

take a look at the answer here. lazy loading images in UITableView iPhone SDK i use in in a few of my apps and it works great

Community
  • 1
  • 1
Jason Bugs Adams
  • 737
  • 1
  • 5
  • 11
  • Apple's LazyTableImages sample project has the same problem. Flick scroll the list, and you'll see the images don't get displayed until scrolling stops. That is the whole problem I'm trying to solve... – bpatrick100 Feb 15 '11 at 18:42
  • this is done for efficiency. but you can alter the code and remove the sections that deal with that. look for the "dragging" and "decelerating" statements. – Jason Bugs Adams Feb 15 '11 at 18:48
  • I have done all that. That is not the problem. I have modified the LazyTableImages sample app to call the async image download immediate when the cell is displayed. My NSLog statements confirm the downloads begin immediately (they don't wait until scrolling stops) However, as I've said, the download callbacks never get fired until scrolling stops. – bpatrick100 Feb 15 '11 at 18:56
  • without seeing your code i cant assume that you made all the proper changes. but i was able to get the your desired affect in a project i did in the past by modifying the apple sources. – Jason Bugs Adams Feb 15 '11 at 19:03
  • I wish I could see your code. Mine is very simple - take the LazyTableImages app, and comment out all the conditions that check for scrolling/decelerating, etc. - and instead call the download process as soon as the cell is displayed. That part all works perfectly. It's the callback the doesn't get fired, until scrolling stops. It is as clear as that. – bpatrick100 Feb 15 '11 at 19:12