-1

How can I add 3 imageviews using SDWebImage into NSArray?

I have my images in this form:

[self.imageView1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"image1"]]
                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

[self.imageView2 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"image2"]]
                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

[self.imageView3 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"image3"]]
                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
Carl Anderson
  • 3,446
  • 1
  • 25
  • 45
Milan1111
  • 185
  • 3
  • 13

2 Answers2

1

SDWebImage has another method with the completion block. Use that method

[self.imageView setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"image1"]]
               placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                      completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

                          //completion code here ...

                          [self.animationArray addObject:image]; // animationArray is an array property
                      }];

Add the image to the animationArray from the completion block

Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
-1

If adding the 3 imageViews to your array is what you are aiming at then your second piece of code should be

  NSArray *animationArray = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.imageView3, nil];

Although using the completion block is being suggested in the answer and maybe the best practice, this approach should also should manage fine considering that your imageWithURL call from SDWebImage will handle the network operation and update the objects when it receives the image.

Vijay Tholpadi
  • 2,135
  • 1
  • 15
  • 20