0

我正在尝试添加一个 Success 和 Error 块来检查图像何时加载,以便我可以使用 NSCache 动态调整图像大小。但是当我尝试

[scribbleImage setImageWithURL: [NSURL URLWithString:scribble[@"scribble_image"]] placeholderImage:[UIImage imageNamed:@"Default.png"] success:^(UIImage *image) {
NSLog(@"done");
} failure:^(NSError *error) {
NSLog(@"error %@",error);
}];

Xcode给我一个错误,说No visible @interface for 'UIImageView' declares the selector 'setImageWithURL:placeholderImage:success:failure:'

我不确定为什么。

PS。我正在导入 UIImageView+AFNetworking.h 并且没有成功和失败块的情况下一切正常

4

1 回答 1

2

这是因为没有方法setImageWithURL:placeholderImage:success:failure:只有setImageWithURLRequest:placeholderImage:success:failure:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:scribble[@"scribble_image"]]];

[scribbleImage setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"Default.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
    NSLog(@"Done");
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
    NSLog(@"Failed with error: %@", error);
}];

如果你看看做什么setImageWithURL:placeholderImage:

- (void)setImageWithURL:(NSURL *)url
       placeholderImage:(UIImage *)placeholderImage
{
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPShouldHandleCookies:NO];
    [request addValue:@"image/*" forHTTPHeaderField:@"Accept"];

    [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
}

您会看到,这也是用于在内部获取的方法。

于 2013-03-14T08:54:59.067 回答