UITableView单元格不会使用setImageWithUrl加载图像

时间:2015-02-28 19:25:14

标签: ios objective-c uitableview uiimageview afnetworking

Iam尝试使用AFNetworking + UIImageview方法获取图像setImageWithURL:

代码是这个

//Get the url from data
NSArray *images = [data valueForKey:@"images"];
NSString *imgUrl = [NSString stringWithFormat:@"%@",[images valueForKey:@"mobile"]];
imgUrl = [imgUrl stringByReplacingOccurrencesOfString:@"\n" withString:@""];
imgUrl = [imgUrl stringByReplacingOccurrencesOfString:@" " withString:@""];
imgUrl = [imgUrl stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSString* webStringURL = [imgUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url = [NSURL URLWithString:webStringURL];

//create request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

//Load cell with image
[cell.imgvwBackground setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"BackLogo"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

    NSLog(@"success");

} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {

    NSLog(@"RESPONSE: %ld \n %@",(long)[response statusCode], error);
}];

我得到的错误是:

2015-02-28 20:18:53.822 Diggit[964:60b] RESPONSE: 0 Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x16694490 {NSErrorFailingURLStringKey=(https://images.bowntycdn.net/images/deals/mobile/24013997/groupon-dk-herremode-loom-joggingbukser-levering-gratis.jpg), NSErrorFailingURLKey=(https://images.bowntycdn.net/images/deals/mobile/24013997/groupon-dk-herremode-loom-joggingbukser-levering-gratis.jpg), NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x166931c0 "unsupported URL"}

因此,我从中获取图像的图像链接为:https://images.bowntycdn.net/images/deals/mobile/24013997/groupon-dk-herremode-loom-joggingbukser-levering-gratis.jpg 但它无法将其视为一种联系。

我试过

[cell.imgvwBackground setImageWithURL:[NSURL URLWithString:imgUrl]];

但是图像也不会起作用。希望你们能帮忙

0 个答案:

没有答案