下午好,
我第一次尝试在我的项目中使用SDWebImage,但最初我认为这很容易,但事实并非如此。这就是为什么我要求你的帮助,因为它不像他们在网站上说的那样工作,而我却迷失了。
首先,我需要SDWebImage,因为我需要从TableViewController异步加载我的图像。
这是我在TableViewController中的UITableView:
#import "SDWebImage/UIImageView+WebCache.h"
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"carTableCell";
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.makeLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"id"];
cell.likes.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"likes"];
cell.comments.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"comments"];
cell.username.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"username"];
cell.refuser.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"user_ref"];
cell.modelLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"user"];
NSURL * imageURL = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"imagen"]];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * carPhoto = [UIImage imageWithData:imageData];
cell.carImage.image = carPhoto;
NSURL * imageURL2 = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"image"]];
NSData * imageData2 = [NSData dataWithContentsOfURL:imageURL2];
UIImage * carPhoto2 = [UIImage imageWithData:imageData2];
cell.profileImage.image = carPhoto2;
// LINES INCLUDED FROM THE SDWebImage website steps:
// Here we use the new provided setImageWithURL: method to load the web image
[cell.carImage setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
// END
return cell;
}
我已经包含了从GitHUB下载的SDWebImage中的所有文件,但是当我写新行时,我收到以下错误:
CarTableViewController.m:82:21: No visible @interface for 'UIImageView' declares the selector 'setImageWithURL:placeholderImage:'
为什么会发生这种情况?如何解决这个问题?
提前致谢。