0

I have used SDWebimages classes for loading the image from url to image view. But it is still taking time to load.

 NSString *filePath1 = [NSString stringWithFormat:@"%@",pathimage1];
 [cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

Can anyone tell me what I am doing wrong? Or the best way to load the image from url.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
Minkle Garg
  • 1,397
  • 3
  • 13
  • 27
  • My firs guess will be that the server sends a `non-cache` header with the image and there for the image is not cahced or you are loading so many images that you cache clear some old image to make room for new ones. – rckoenes Aug 23 '13 at 11:43
  • @rckoenes but its working fine for android app – Minkle Garg Aug 23 '13 at 11:50
  • @MinkleGraf It might be that Android does look at the cache headers. You might just want to check them, at least it will eliminate that it is the cache header. – rckoenes Aug 23 '13 at 11:52

2 Answers2

0

Try this :

NSString *filePath1 = [NSString stringWithFormat:@"%@",pathimage1];

[cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]]
                placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                         success:^(UIImage *image, BOOL cached) 
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                cell.image1.image = image;
            });
            NSLog(@"success Block");
        }
                         failure:^(NSError *error) 
        {
            NSLog(@"failure Block");
        }];
Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
0

Loading images from the network may take a long time to load for several reasons, two of the most obvious being

  • Slow connection to the internet on the device (Wifi / 3G / 2G).
  • Overloaded server.

To speed things up if you have control over the server and the images that are stored on it you could always load a smaller version (low quality preview/thumbnail) initially, followed by loading a larger / full-size version when needed:

typedef enum {
  MyImageSizeSmall,
  MyImageSizeMedium,
  MyImageSizeLarge
} MyImageSize;

-(void)requestAndLoadImageWithSize:(MyImageSize)imageSize intoImageView:(UIImageView *)imageView
{
  NSString *imagePath
  switch (imageSize)
  {
    case MyImageSizeSmall:
      imagePath = @"http://path.to/small_image.png";
    break;
    case MyImageSizeMedium:
      imagePath = @"http://path.to/medium_image.png";
    break;
    case MyImageSizeLarge:
      imagePath = @"http://path.to/large_image.png";
    break;
  }
  [imageView setImageWithURL:[NSURL URLWithString:imagePath]
            placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
Steve Wilford
  • 8,894
  • 5
  • 42
  • 66