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

4

你好,我在新的Xcode和AFNetworking中遇到了问题。 在xcode5中,我没有遇到这些问题,但是我开始进行一些更改和更新。 问题是:

'UIImageView'没有声明名为'setImageWithURL'的选择器

代码如下:

  NSString *showThumb = [[[[SettingDataClass instance] getSetting] objectForKey:@"appearance_option"] objectForKey:@"category_browse_show_thumb"];
if([showThumb isEqualToString:@"show"])
{
UIImageView *img = [[UIImageView alloc] init];
img = cell.imageView;
[cell.imageView setImageWithURL:[NSURL URLWithString:[[ToolClass instance] decodeHTMLCharacterEntities:[[aryDic objectAtIndex:indexPath.row] objectForKey:@"thumb"]]]
        placeholderImage:[UIImage imageNamed:NSLocalizedString(@"image_loading_placeholder", nil)]
               completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

                   img.image = [[ToolClass instance] imageByScalingAndCroppingForSize:CGSizeMake(57, 57) source:image];

               }];

在哪里可能出现问题,为什么这段代码在Xcode6中无法运行? 非常感谢您的帮助。
3个回答

9
尝试在使用该方法的文件中包含"UIImageView+AFNetworking.h"

我在react-native上遇到了同样的问题,有什么帮助吗? - Nicks

0
这是关于UIImageView的苹果文档。正如您所看到的,没有像setImageWithURL这样的方法。 AFNetworking有一个UIImageView的子类。它有一个名为setImageWithURL的方法。如果您想使用此方法,需要导入该类。希望这可以帮助您.. :)
你应该写成这样:
img = cell.imageView;
[cell.imageView setImageWithURL:[NSURL URLWithString:[[ToolClass instance] decodeHTMLCharacterEntities:[[aryDic objectAtIndex:indexPath.row] objectForKey:@"thumb"]]]
        placeholderImage:[UIImage imageNamed:NSLocalizedString(@"image_loading_placeholder", nil)]
               completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

                   img.image = [[ToolClass instance] imageByScalingAndCroppingForSize:CGSizeMake(57, 57) source:image];

               }];

并且你的单元格应该具有一个类型为UIImageView+AFNetworking的imageView。


UIImageView+AFNetworking *img?这不是分类的使用方法。 - mattt

0

UIImageView 不是那样工作的。您需要添加 AFNetworkingUIImageView 类别才能使用 setImageWithURL 方法。


请问您能详细说明一下吗? - arpit

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