0

I am using ASIHTTPRequest, i have to populate my table with images. So people at forums suggest to cache the image to increase the performance.

I have no clue how to do this. I will be able to do this if someone helps me with some sample code or give me a link to a tutorial that explains this well. Help

You might think this is duplicate, in fact i too found many similar questions of SO, like this, but none of these helped.

Community
  • 1
  • 1
Illep
  • 16,375
  • 46
  • 171
  • 302
  • Use SDWebImage https://github.com/rs/SDWebImage Instructions are available on github.. I have used it..works great. – Shubhank Feb 20 '12 at 15:19
  • I have used this, it didn't help. I have given the task to load some images to a tableview. So i thought of caching since it will be very quick and also will have a glassy effect. – Illep Feb 20 '12 at 15:49
  • how it didn't help?? this library caches the images..so next time cell is shown..the image won't be downloaded again...what is the problem? – Shubhank Feb 20 '12 at 15:53
  • I found it to be a little slow, so i used a dispatch queue for downloading and it was a bit faster than SDWebImage. Correct me if i am wrong. (i am still learning) – Illep Feb 20 '12 at 16:14
  • dispatch might be faster haven't tried it..for me SDWebImage was good..since it involves just one line of code. – Shubhank Feb 20 '12 at 16:21
  • Do you believe that dispatch is faster ? I have tried both approaches and i think it is faster, but i need someone to tell me if i am doing the correct thing :S – Illep Feb 20 '12 at 16:23
  • well i haven't tried dispatch yet..but i think SDWebImage itself uses dispatch..if dispatch works better for you use it..both approach are good..another reason of slow scrolling might be if image comes in high resolution and size and have to be reconverted to appropriate sizes..check into that too. – Shubhank Feb 20 '12 at 16:27
  • Yes, i have set my UIImageView to a thumbnail size. and i load the image to it. – Illep Feb 20 '12 at 16:36
  • you might have set it to size of lets say 30 x 30 ..but if image comes in 500 x 500 then it would have to converted to size of 30 x 30 ..which might scroll down your scrolling..check into that – Shubhank Feb 20 '12 at 16:41
  • Yes, this is exactly what is hapenning. What should i do to make the image to 30x30 and also if i use SDWebImage should i worry about it ? – Illep Feb 20 '12 at 16:46

2 Answers2

0

Basically, you keep a dictionary with keys being the cell # and it's object being image. Right when you are about to make a request for an image, first check if it already exists in your dictionary. If it does, simply use that, otherwise, download the image and stick it inside your dictionary.

0xSina
  • 20,973
  • 34
  • 136
  • 253
0

Simply keep an array of objects that contain all of the information that you want to be shown in the table view. This array can contain objects that hold all of the information that you may need, such as pictures, whether or not the picture has been loaded, labels. Really anything you want. Just make sure that once you are done with the array though that it does get released, which is not much of an issue in iOS 5, but if you are using anything older than that, be sure to release it or at least set the array to nil after.

MZimmerman6
  • 8,445
  • 10
  • 40
  • 70