0

Normally I can set the background image of a UITableView using

 [self.tableView setBackgroundView:imageView];

Also, using SDWebImage I can add an image to a UIImageView in two steps:

#import "SDWebImage/UIImageView+WebCache.h"
...
[self.myImageView sd_setImageWithURL:imageURL];

But now I need to add a background image to a UITableView using SDWebImage. How might I do that?

learner
  • 11,490
  • 26
  • 97
  • 169

2 Answers2

1

Call the same method on the UIImageView that's being set as the UITableView's background view.

// a)
[self.tableView setBackgroundView:[UIImageView new]];
[(UIImageView *)self.tableView.backgroundView sd_setImageWithURL:imageURL];

// b)
UIImageView *backgroundView = [UIImageView new];
[backgroundView sd_setImageWithURL:imageURL];
[self.tableView setBackgroundView:backgroundView];
max_
  • 24,076
  • 39
  • 122
  • 211
  • haha. I actually tried that but I got a compile error for `self.tableView.backgroundView`. Apparently there is no such property. But thanks. – learner Aug 26 '14 at 02:19
  • I see, you'll need to cast it as a UIImageView then, or call the method on the instance before it's set. FYI it would be beneficial to the community if you could accept answers on your previous questions. It will also encourage others to answer your questions. – max_ Aug 26 '14 at 02:21
0
[self.tableView setBackgroundView:[UIImageView new]];
[(UIImageView *)[self.tableView backgroundView] sd_setImageWithURL:imageURL];

There is no property, but there is a method.

Konsol Labapen
  • 2,424
  • 2
  • 15
  • 12