3

Iam using collectionview to load image.These images are loaded from url in background thread. Hence the scrolling is not smooth.The images in url get expired after seconds hence i want to update the image with new image.How can i use the SDWebImage to load image and make scrolling smooth? Can anyone please help me to solve this.

user1728987
  • 329
  • 3
  • 9

2 Answers2

1

Use this code

[YOUR_CELL_NAME.YOUR_IMAGE_NAME setImageWithURL:[NSURL URLWithString:@"IMAGE URL"] placeholderImage:[UIImage imageNamed:@"PLACEHOLDER IMAGE NAME"]];
0

You need to integrate the sdwebimage classes in your code. After that make a import.

Download sdwebimage from here

#import "UIImageView+WebCache.h"

and in your collectionview method write following lines to download image in backend thread.

[YOUR_CELL_NAME.YOUR_IMAGE_NAME setImageWithURL:[NSURL URLWithString:@"IMAGE URL"] placeholderImage:[UIImage imageNamed:@"PLACEHOLDER IMAGE NAME"]];
Raza.najam
  • 769
  • 6
  • 15
  • Yes I did that, but the image that are loaded are all expired images. i want to download image and save it. i have no idea in code where this saving actually happens. – user1728987 May 25 '16 at 09:47
  • 1
    You need to clear the cache. SDImageCache *imageCache = [SDImageCache sharedImageCache]; [imageCache clearMemory]; [imageCache clearDisk]; – Raza.najam May 25 '16 at 09:48
  • Once i get an image downloaded it is shown in all imageviewsvof collection view cells.But iam passing different urls – user1728987 May 25 '16 at 10:01
  • I want to save the image using an inter value .Can someone please help, – user1728987 May 25 '16 at 12:51