1、下载SDWebImage
下载地址:https://github.com/rs/SDWebImage
2、项目导入相关文件
(1)在Target->Build Phases->Link Binary with Libraries中添加 ImageIO.Framework 和MapKit.Framework
(2)项目中导入SDWebImage文件夹
3、修改Build Settings
target->Build Settings->Linking目录下的Other Linker Flags里面添加:-ObjC
4、查看官方给的readme文档
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.textLabel.text = @"My Text";
return cell;
}
修改文档中红色部分
(1)在官方给出SDWebImage是支持ARC的 所以去掉项目中 autorelease
(2)查看SDWebImage中的源码发现 setImageWithURL 已经改为了 sd_setImageWithURL 所以把文档的代码进行相应修改后 放入项目 运行成功。