SDWebImage 初步使用 及发现readme文档中的问题

本文详细介绍了如何在iOS项目中下载并导入SDWebImage框架,包括设置依赖库、修改构建设置以及如何正确调用其功能加载网络图片。重点突出通过更新文档代码来适应框架的新特性,并在实际项目中成功运行,达到优化图片加载效率的目的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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     所以把文档的代码进行相应修改后 放入项目  运行成功。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值