2

I have a problem with loading of 5 images to each cell of TableView. I use AFNetworking for download and setImageWithUrl method for imageView:

for (int i = 0; i < urls.count; i++) {
    [self.photoImageView[i] setImageWithURL:urls[i]];
}

TableView very brakes when I scroll it. But when i try to load 1 or 2 no brakes when scrolling. enter image description here How to correct download images without brakes?

Ravi Dhorajiya
  • 1,531
  • 3
  • 21
  • 26
Alex
  • 21
  • 5

4 Answers4

2

I think's it's helpful for you below the code work for me.

First fall you use this library SDWebImage then implement below code.

#import <SDWebImage/UIImageView+WebCache.h>
...
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"URL"]
             placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
Ravi Dhorajiya
  • 1,531
  • 3
  • 21
  • 26
1

You can use SDWebImage as discussed by @Ravi. You can use use the above code in your for loop to display all 5 images asynchronously , without blocking main thread.

for (int i = 0; i < urls.count; i++) {
[self.photoImageView[i] sd_setImageWithURL:[NSURL URLWithString:urls[i]]
         placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}

If you dont want to use any third party libraries, you can also use GCD for the same. Check this ans.

Hope it helps. Happy Coding!!

luckyShubhra
  • 2,731
  • 1
  • 12
  • 19
0

If you see UIImage + AFNetworking class,It internally loads image using Async NSOperations.Try loading image with specific dimensions.It will download image of that size & could improve scrolling performance.

NSMutableString *newURLPath = [NSMutableString stringWithString[exercise.imageURL absoluteString]];
 [newURLPath appendFormat:@"?width=200&"];
 [newURLPath appendFormat:@"height=200"];
Ellen
  • 5,180
  • 1
  • 12
  • 16
0

For downloading the Asynchronous image from url, use any of these library for improving the scroll performance

SDWebImage - Asynchronous image downloader with cache support as a UIImageView category.

#import <SDWebImage/UIImageView+WebCache.h>
...
[imageView sd_setImageWithURL:URL
             placeholderImage:[UIImage imageNamed:@"placeholder.png"]
];

PINRemoteImage - It download a progressive jpeg and get attractive blurred updates.

For in your case, you can go for SDWebImage.

For Advance Concept, you could look into this one.

AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps

Even recently, Pinterest was built on top of AsyncDisplayKit to Keeps UIs smooth and responsive. Read this article for more info: https://medium.com/@Pinterest_Engineering/re-architecting-pinterest-039-s-ios-app-e0a2d34a6ac2

Balasubramanian
  • 5,274
  • 6
  • 33
  • 62