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"]];
}