1

I'm a noob to iphone development and I am trying to implement the SDWebImage library into my project. My project builds fine, however it when I display my tableview my app crashes with an invalid argument exception. I followed the installation instructions thoroughly. I added the ImageIO framework, added the -fobjc-arc flag since my project is non-ARC, and imported the appropriate header. Any help is greatly appreciated.

MY Exception

'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x6e47d50'

My Code

 // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

//Lazy Loader
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
               placeholderImage:[UIImage imageNamed:@"mylogo.png"]];

// Configure the cell...

NSDictionary *aTweet = [tweets objectAtIndex:[indexPath row]];

cell.textLabel.text = [aTweet objectForKey:@"text"];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.textLabel.minimumFontSize = 10;
cell.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;

cell.detailTextLabel.text = [aTweet objectForKey:@"from_user"];

NSURL *url = [NSURL URLWithString:[aTweet objectForKey:@"profile_image_url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
cell.imageView.image = [UIImage imageWithData:data];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
B. Money
  • 931
  • 2
  • 19
  • 56

1 Answers1

2

Inside the top of that file, have you included the SDWebImage header, ie:

#import <SDWebImage/UIImageView+WebCache.h>

(if you are using cocoapods.. otherwise something like:)

#import "SDWebImage/UIImageView+WebCache.h"

or

 #import "UIImageView+WebCache.h"

edit:

Why have you got this code at the top:

[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
               placeholderImage:[UIImage imageNamed:@"mylogo.png"]];

when you have this setting it again at the bottom:

NSURL *url = [NSURL URLWithString:[aTweet objectForKey:@"profile_image_url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
cell.imageView.image = [UIImage imageWithData:data];

you dont need both - perhaps remove the code that is at the bottom that doesnt use the lazy loader?

dotbill
  • 1,001
  • 7
  • 13
  • I already have #import in my implementation. – B. Money Mar 07 '13 at 13:23
  • do add -ObjC in other linker flag in build settings as if you have static library with uikit in it we need to bypass it as external library flag, http://developer.apple.com/library/mac/#qa/qa1490/_index.html – Jay Sampat Jul 04 '13 at 13:42