异步图像下载程序错误Obj-c SDWebimage

时间:2017-12-05 03:19:06

标签: uitableview asynchronous sdwebimage

我在一个简单的应用程序中工作,在tableview中显示产品,我从json api获取数据。问题是由于图像的同步下载,表格变得迟钝。我试图使用SDWebimage框架来解决这个问题,但我得到了这个错误:

"' NSInvalidArgumentException',原因:' - [UIImageView sd_setImageWithURL:placeholderImage:]:无法识别的选择器发送到实例"

我的代码是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    NSDictionary *dictionary = [self.json objectAtIndex:indexPath.row];
    cell.textLabel.text=[dictionary objectForKey:@"name"];
    cell.detailTextLabel.text = [dictionary objectForKey:@"description"];

    //old synchronous code
   /* NSString *path = [[[[dictionary objectForKey:@"images"] objectAtIndex:0] valueForKey:@"thumb"] valueForKey:@"url"];
    NSString *ruta = [NSString stringWithFormat:@"http://18.221.78.126/ecoferia%@",path];
    NSURL *url = [NSURL URLWithString:ruta];
    NSData *imgData = [NSData dataWithContentsOfURL:url];
    cell.imageView.image = [UIImage imageWithData:imgData];
    */

    //trying to do asynchronous download of the images
    NSString *path = [[[[dictionary objectForKey:@"images"] objectAtIndex:0] valueForKey:@"thumb"] valueForKey:@"url"];
    NSString *ruta = [NSString stringWithFormat:@"http://18.221.78.126/ecoferia%@",path];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:ruta]
                 placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    return cell;
}

我也在我的proyect中安装了SDWebimage并导入.m文件中,如下所示:

#import "SDWebImage/UIImageView+WebCache.h"

我对objective-c非常新,所以所有提示都很受欢迎。

关于..

1 个答案:

答案 0 :(得分:0)

解决方案是将$(继承)置于Build Settings - >其他链接器标志。 工作得好:)