Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The issue may be that the images are just too big. What you may want to do is resize the image from the downloaded image before setting the image property on each UIImageView.</p> <p>Bill Dudney published a very useful iBook on the topic which goes into detail on the consequences of images on memory and how to optimize for it. It is $4.99 and very helpful.</p> <p><a href="https://itunes.apple.com/us/book/all-image-io-you-need-to-know/id601759073?mt=11" rel="nofollow">https://itunes.apple.com/us/book/all-image-io-you-need-to-know/id601759073?mt=11</a></p> <p>The following method will resize an image to the given size which will decrease the memory footprint and hopefully prevent your issue.</p> <pre><code>- (UIImage *)resizeImage:(UIImage *)image size:(CGSize)size { UIGraphicsBeginImageContext(size); [image drawInRect: CGRectMake(0, 0, width, height)]; UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resizedImage; } </code></pre> <p>Now if you are using AFNetworking to set the image directly from the URL using the AFNetworking category you may want to use the alternate method so you can intervene and resize the image. The code below will do that.</p> <pre><code>NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:imageURL]; [request addValue:@"image/*" forHTTPHeaderField:@"Accept"]; [imageView setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { // resize image // set image on imageView } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { // handle error }]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload