【问题标题】:Using UIImageView with SDWebImage将 UIImageView 与 SDWebImage 一起使用
【发布时间】:2014-11-12 05:11:49
【问题描述】:

下午好,

我正在尝试在我的 TableViewController 中实现 SDWebImage,但由于我的 UiImageView 导致我无法检测到问题,我遇到了一些错误,我需要一些帮助。我希望你能找到一些东西,因为我现在迷路了。

我收到以下错误:

“UIImageView”没有可见的@interface 声明选择器“sd_setImageWithURL:placeholderImage:”

应用程序运行正常,缓存运行正常,但我收到了该错误。

如果我已经将“carImage”设置为 UIImageView,为什么会发生此错误?我该如何解决?

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;
}

这是我的 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

提前致谢。

【问题讨论】:

  • 您能检查一下库搜索路径...还是框架搜索路径?您的 Project + Target + TestSuite 构建设置都指向 SDWebImageFramework 吗?我记得上次我错过了我的 TestSuite 框架的路径,它抱怨找不到框架。

标签: ios xcode uitableview xcode6 sdwebimage


【解决方案1】:

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

#import <SDWebImage/UIImageView+WebCache.h>

【讨论】:

  • 我已经这样做了,但我仍然有这个错误。谢谢@0x52
  • 对我来说 IBOutlet 是 UIView 而不是 UIImageView
  • 我遇到了同样的问题。
【解决方案2】:

确保您正在导入包含您尝试调用的 sd_xxxx 类别方法的头文件。

试试这个:

@implementation SomeClass

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

@end

你会得到相同类型的错误。

【讨论】:

  • 我可以点击我的 sd_ 方法,然后我会被重定向到我项目中的文件。为什么这仍然不起作用?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
  • 1970-01-01
  • 2014-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多