0

I am using SDWwbImage, wich i download from here:

https://github.com/rs/SDWebImage

I tested in the method: cellForRowAtIndexPath and everything works fine, here is my code:

[cell.image setImageWithURL:[NSURL URLWithString:object.imageUrl]];

Now i need to call an image outside this method (eg: heightForRowAtIndexPath, viewDidLoad), and i always get no image, here is my code:

UIImageView *test = [[UIImageView alloc] init];
[test setImageWithURL:[NSURL URLWithString:categories.imageUrl]];
NSLog(@"height: %f", test.image.size.height);

Is it disallowed to use setImageWithURL anywhere? how can i solve this?

EDITED

I tried to add the completion block to know when the download is finished and refresh the uitablevew, here is my code:

UIImageView *test = [[UIImageView alloc] init];
        [test setImageWithURL:[NSURL URLWithString:object.imageUrl]
                       placeholderImage:[UIImage imageNamed:@"ic_launcher_57@2x.png"]
                              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
                                  counterY++;
                                  if (counterY == counterX) {
                                      NSLog(@"reloading");
                                      [self.tableView reloadData];
                                  }
        }];

But only the first time the controller is loaded, this doesnt work. Every time after this everything is fine.It looks like something cancel de download the first time.

Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75
  • `setImageWithURL` actually does the magic of downloading the image asynchronously, so the image is not immediately available. You'll need to make other arrangements, or check the `SDWebImage` documentation for some way of being notified when the image is actually available. – David Berry May 30 '14 at 20:37
  • Not sure what you have going on with counterX and Y, but that's definitely suspect. – David Berry May 31 '14 at 06:48

0 Answers0