I am facing the issue ,below is the code. It shows error for the very first time and then no completion block is calling .
[self.comicsImage setImageWithURL:[NSURL URLWithString:self.imageUrl]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
Please help. If the image is not on the server it shows error first time then it does nothing on again requesting the same URL.Thanks in advance.
Because it caches the retured image for the requested url, 2nd time it returns what is in the cache for the given url.
Try this code, it should work for you
[self.comicsImage setImageWithURL:[NSURL URLWithString:self.imageUrl]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
if (cacheType == SDImageCacheTypeNone)
{
//your code here
}
}];
Related
in my application i am downloading an image from url from webservice using SDWebImage Library. I have nothing problem with this code
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:#"url"] placeholderImage:#"abc.png" options:SDWebImageProgressiveDownload];
with above code i have successfully load the image in imageview...
But my problem is that if i have url for the image but image is not available at that particular path of url. So, how to know that image is not available so i can load next data.
Thanks.
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
success:^(UIImage *image) {
if(image){
}else{
}
}
failure:^(NSError *error) {
}];
];
This is what exactly i wanted.
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:[[arrOfLoadedPuzzel objectAtIndex:0] objectForKey:#"puzzle_question"]]
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
if(error)
{
// image is not available
}
else
{
// image is available
}
}];
I tried over 100 methods to animate images using SDWebImage but always fail. Do I understand good to using blocks? I am having IBOutlet property image names images1. I made array to store values and animate 3 images.
NSMutableArray *imagegallery = [[NSMutableArray alloc] init];
NSLog(#"IMAGES-%#", imagegallery);
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img1"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
NSLog(#"Ima1-------%#", image);
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img2"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img3"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
self.images1.animationImages = imagegallery; //this line gets error
self.images1.animationDuration = 0.5;
[self.view addSubview:self.images1];
[self.images1 startAnimating];
I think when you set self.images1.animationImages = imagegallery because your image couldn't be loaded yet, method setImageWithURL:placeholderImage:completed: is an asynchronous function. you should try another way
like:
Animate images in uiimageview
The problem is that imageGallery contains strings as well as the images you add in the completed block. There's no reason to set imageGallery to be a copy of animatee in the first place since you never use those strings in imageGallery. Just create a new empty mutable array for imageGallery.
I am trying to show progress view with SDWebImage but when i try below code then it return "0" in "receivedSize"
[cell. ImageHotDish setImageWithURL:[NSURL URLWithString:picName]
placeholderImage:[UIImage imageNamed:nil]
options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {
NSLog(#"Downloaded = %#",receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[cell.ImageHotDish setImageWithURL:[NSURL URLWithString:picName]];
}];
I am getting null velue in "receivedSize"
Can any one tell me where i am doing wrong
I have already check this solution but its not showing progress but just an activity indicator. What i am trying to get how much image have been downloaded.
Show activity indicator in SDWebImage
I have latest version of SDWebimage but it doesnt have Success & failure
I tried the following method but SDwebimage doesnt have method
[self.imageView setImageWithURL:[NSURL URLWithString:self.imageURL]
placeholderImage:[UIImage imageNamed:#"YourPlaceholder.png"]
success:^(UIImage *image) {
// remove animation
}
failure:^(NSError *error) {
NSLog(#"thumbnail error: %#",error);
// handle failed download
}];
Does anybody know how to add success & failure block in SDwebimage setImageWithURL or any other alternatife
I want to handle if there is some error while getting image from URL
Try this:
[self.imageView setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:#"YourPlaceholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//... completion code here ...
}];
Solution for Swift 3 :
cell.imageView?.sd_setImage(with: url) { (image, error, cache, urls) in
if (error != nil) {
//Failure code here
cell.imageView.image = UIImage(named: "ico_placeholder")
} else {
//Success code here
cell.imageView.image = image
}
}
Solution for Objective C :
[cell.imageView sd_setImageWithURL:url
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error) {
//Failure code here
self.imageView.image = [UIImage imageNamed:#"ico_placeholder"];
} else {
//Success code here
self.imageView.image = image;
}
}];
Hope you guys find this useful.
imageView.sd_setImageWithURL(NSURL(string: urlString), completed: {
(image, error, cacheType, url) in
// do your custom logic here
})
sample code for swift 2.0
it has completion block
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
You can check if error is nil, then everything is fine.
I am using SDWebImage to cache my images. Overall it looks good but when I use setImageWithUrl method, it take a bit longer to bind the image back to my collection view. Is there a solution to this problem? I tried the following, but looks like it's still having the same problem.
__weak UIImageView *weakImageView = pictureImageView;
[pictureImageView setImageWithURL:[NSURL URLWithString:picture.attachment.url] placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
weakImageView.image = image;
}];