'UIImageView'没有可见的@interface声明选择器'setImageWithURL'

4

下午好,

我正在尝试在我的TableViewController中使用 SDWebImage ,但是我遇到了两个错误(每个图像元素一个错误),但我可以运行应用程序并且可以看到 SDWebImage 正常工作,但是伴随着这两个错误。

这怎么可能?我真的很高兴 SDWebImage 工作了,但我不知道它为什么会显示这些错误然后又工作了。

此外,当我使用“setImageWithURL”时,那两个错误也出现了(但未链接该函数),但当我使用“sd_setImageWithURL”时则不起作用,并且我还有那两个错误(但 sd_setImageWithURL 链接到 SDWebImage 文件)。

那么,我应该使用哪一个?因为我想让它正常工作,但又不想有任何错误。

我收到以下错误:

'UIImageView'没有声明选择器“setImageWithURL:placeholderImage:options:”

以下是一些代码:

CarTableViewController.m

#import "CarTableViewController.h"
#import "CarTableViewCell.h"
#import "CarTableViewController.h"
#import "CarDetailViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>

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

    [cell.carImage setImageWithURL:imageURL

                  placeholderImage:[UIImage imageNamed:@"placeholder.png"]

                           options:SDWebImageRefreshCached];



    NSURL * imageURL2 = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"image"]];


    [cell.profileImage setImageWithURL:imageURL2

                      placeholderImage:[UIImage imageNamed:@"image"]

                            options:SDWebImageRefreshCached];



    return cell;

}

这是我的 CarTableViewCell.h 文件:
#import <UIKit/UIKit.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

提前致谢。

1个回答

5

您需要调用

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

谢谢你的回答@I0gg3r,但我不明白你的意思。所以我必须复制那段代码而不是我的?但我认为它是一样的,对吧?问候。 - Lock_85_Dr
请注意,我已经在方法调用上添加了 sd_ 前缀,现在应该可以正常工作了。 - l0gg3r
再次感谢@I0gg3r。我将尝试这个方法,但我认为昨天我已经尝试过了,但仍然出现了相同的错误(但当我点击sd_setImageWithURL时,它可以正确显示SWebImage文件)。您知道为什么会出现这个错误吗?谢谢。 - Lock_85_Dr
尝试按下“cmd + k”清理项目,然后重新构建。应该可以解决问题。 - l0gg3r
好的,我会试一下。谢谢 ;) - Lock_85_Dr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接