简体   繁体   English

将UIImageView与SDWebImage一起使用

[英]Using UIImageView with SDWebImage

Good afternoon, 下午好,

I'm trying to implement SDWebImage in my TableViewController but I'm having some errors due to my UiImageView that I'm not able to detect the problem and I need some help with that. 我正在尝试在TableViewController中实现SDWebImage,但是由于我的UiImageView而导致一些错误,导致我无法检测到该问题,因此我需要一些帮助。 I hope you can find something because I'm lost at the moment. 希望您能找到一些东西,因为我现在迷路了。

I'm getting the following error: 我收到以下错误:

No visible @interface for 'UIImageView' declares the selector 'sd_setImageWithURL:placeholderImage:' 'UIImageView'的可见@interface没有声明选择器'sd_setImageWithURL:placeholderImage:'

The app is working and the cache is working fine but I'm getting that error. 该应用程序正在运行,缓存运行正常,但出现了该错误。

Why is this error happening if I have already set my "carImage" to UIImageView? 如果已经将“ carImage”设置为UIImageView,为什么会发生此错误? How can I solve it? 我该如何解决?

CarTableViewController.m CarTableViewController.m

- (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];

// ERROR    [cell.carImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    NSURL * imageURL2 = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"image"]];
    NSData * imageData2 = [NSData dataWithContentsOfURL:imageURL2];
    UIImage * carPhoto2 = [UIImage imageWithData:imageData2];

    cell.profileImage.image = carPhoto2;

    return cell;
}

That's my CarTableViewCell.h : 那就是我的CarTableViewCell.h

@interface CarTableViewCell : UITableViewCell

@property (nonatomic, strong) IBOutlet UIImageView *carImage;
@property (nonatomic, strong) IBOutlet UILabel *makeLabel;
@property (nonatomic, strong) IBOutlet UILabel *modelLabel;

@property (nonatomic, strong) IBOutlet UILabel *likes;
@property (nonatomic, strong) IBOutlet UILabel *comments;
@property (nonatomic, strong) IBOutlet UILabel *username;
@property (nonatomic, strong) IBOutlet UILabel *refuser;
@property (nonatomic, strong) IBOutlet UIImageView *profileImage;

@end

Thanks in advance. 提前致谢。

您必须导入UIImageView类别,以便编译器可以看到它:

#import <SDWebImage/UIImageView+WebCache.h>

Make sure you're importing the header file that contains the sd_xxxx category methods you're trying to call. 确保要导入的头文件包含要尝试调用的sd_xxxx类别方法。

Try this: 尝试这个:

@implementation SomeClass

-(void)doSomething {
    UIView *view = [[UIView alloc] init];
    [view doSomethingCool];
}

@end

You will get the same type of error. 您将得到相同类型的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM