0

I'll try to explain my self, I have ContactsViewController that shows a table view with a list of contacts (the model is an array of Contact objects), each cell display an image of a contact.

Currently what I do to populate the cell's UIImageView is this:
1. I override the Contact image property getter -

- (UIImage *)contactImage
 {
     if (!_contactImage) {
        _contactImage = [[UIImage imageNamed:@"placeHolder.png"] retain];
       [self asyncDownloadContactImageFromServer];
     }
     return _contactImage;
 }
  1. Then when I finish downloading the image I set it to the contactImage property and I post a ContactUpdatedImageNotification.

  2. My ContactsViewController then get this notification and reload the cell of this contact, this will set the downloaded image to the cell's imageView.

The result of this is good async fetching of the images without blocking the UI while the user scroll the table view.
BUT there is something small that bothers me, when the a user scroll the table view and reveal new cells the new cell's image get download as expected but the cell's imageView is not updated with the new downloaded image till the user pick up his finger.
I supposed that I need to do something in another thread to make this effect, but I don't know how?

Eyal
  • 10,777
  • 18
  • 78
  • 130

2 Answers2

1

The image is not updated until the user stops scrolling due the code being executed in the default runloop, which gets delayed until scrolling finishes. This other question deals with the difference between the runloops, NSDefaultRunLoopMode vs NSRunLoopCommonModes and it precisely recommends not updating the images while scrolling since that can introduce jerkiness in the scrolling itself if you are not careful.

Also, now that you know about the existence of these runloop modes you will be able to find much more information about them in the xcode documentation or internet.

Community
  • 1
  • 1
Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78
  • > it precisely recommends not updating the images while scrolling - So you say that the way I did it is better? Still I didn't how to update while scrolling do you have some line to an example? – Eyal Apr 19 '12 at 08:02
0

Hey Eyal visit following url...you will get answer and as well sample code...

tableview with different cell with different images

Hope this will help you...

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • use this link.....>>http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial – Nitin Apr 15 '12 at 12:07