Reputation: 1317
I have showed collections of URLImage
in tableview
cell. It is stuck while I am scrolling the cell. I have used third parties like SDWebImageManager
and AFNetWorking
. Never the less the cell has been stuck.
[imageVw setImageWithURL:[NSURL URLWithString:self.imgaeRecord.PreviewURl]placeholderImage:[UIImage imageNamed:@"default-thumbnail.jpg"]];
OR
NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
cell.recipeImageView.image = image;
}
}];
Upvotes: 1
Views: 164
Reputation: 744
I think your problem remains with the performance of the tableview when you have to do many image requests operations. So, in order to optimize the requests you should cancel the request that are being made when the cell leaves the visible area of the tableview. To accomplish that, in your custom cell implement - (void)prepareForReuse
method and in there, assuming that you are using SDWebImage, do [imageView sd_cancelCurrentImageLoad]
. Also, to download and assign the image to the ImageView
you only need to do
[cell.imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]]
Upvotes: 1
Reputation: 798
In your cellForRowAtIndexPath
NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
TableViewCellClass *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell)
updateCell.yourImageView.image = image;
});
}
}
}];
[task resume];
Upvotes: 1
Reputation: 2689
Try to use SDWebImage in this way inside cellForRowAtIndexPath
method
NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];
[cell.imageView sd_setImageWithURL:url
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
cell.recipeImageView.image = image
}];
Upvotes: 1