I'm using UICollectionView
.
Images are coming from FTP server. Here is my code for downloading and Showing image on button :
[tempp sd_setImageWithURL:[NSURL URLWithString:[[arrFilterData objectAtIndex:indexPath.row] valueForKey:@"ZoomPrdImg"]] //PrdImg //ZoomPrdImg
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image) {
myCell.image.userInteractionEnabled = YES;
dispatch_async(dispatch_get_main_queue(), ^{
[myCell.image setImage:image forState:UIControlStateNormal];
[myCell setNeedsLayout];
});
}
}];
myCell.image
is my button that set downloaded image. Now I don't get that image is successfully dowloaded but nut show in button. There's 3000+ images in UICollectionView
but it shows some image and some blank.
How this possible ? How to solve this ? What is issue there ?
EDIT: tempp is allocted in viewDidLoad
- (void)viewDidLoad {
tempp = [[UIImageView alloc] init];
}
replace
[myCell.image setImage:tempp.image forState:UIControlStateNormal];
[myCell setNeedsLayout];
with
[myCell.image setImage:image forState:UIControlStateNormal];
[myCell setNeedsLayout];
Because in your completion handler you are getting your image in image
object
I think your variable tempp is destructed, and cancels request for the image. Change request code to
[myButton sd_setImageWithURL:[NSURL URLWithString:@"MyURL"] forState:UIControlStateNormal completed:yourCompletitionBlock];
And all should be fine.
UPD
Based on your answer about tempp variable, I think you see one Image per page, because when you call sd_setImage... for many cells, only last request is loading. Requests are asynchronous and if you request new image, old request is cancelled.
Code from SDWebImage:
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
[self sd_cancelCurrentImageLoad];
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
First line cancels old request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.