为什么SDWebImage与UITableView导致异常?

时间:2013-03-06 21:18:25

标签: iphone uitableview exception imageview sdwebimage

我是iphone开发的小伙子,我正在尝试将SDWebImage库实现到我的项目中。我的项目构建正常,但是当我显示我的tableview时,我的应用程序崩溃时出现无效的参数异常。我彻底遵循了安装说明。我添加了ImageIO框架,添加了-fobjc-arc标志,因为我的项目是非ARC,并导入了相应的标头。非常感谢任何帮助。

我的例外

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

我的代码

 // 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;
}

1 个答案:

答案 0 :(得分:2)

在该文件的顶部,您是否包含了SDWebImage标头,即:

#import <SDWebImage/UIImageView+WebCache.h>

(如果您正在使用cocoapods ..否则类似于:)

#import "SDWebImage/UIImageView+WebCache.h"

 #import "UIImageView+WebCache.h"

编辑:

为什么你在顶部有这个代码:

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

当您在底部再次进行此设置时:

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

你不需要两者 - 也许删除不使用延迟加载器的底部代码?