0

如果我静态给出,下面的代码可以正常工作,但是

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://4cing.com/mobile_app/uploads/pageicon/6.jpg"]]]];

相同的代码 - 我正在动态传递图像 url 名称它不起作用

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]]]];
4

3 回答 3

0

您需要验证NSArray内容。注销数组的对象:

NSLog(@"imagename = %@",[imagename description]);

此外,附带说明 - 可能需要考虑动态加载该图像。我写了一个类,使这非常轻松:

https://stackoverflow.com/a/9786513/585320

答案是针对使用 in TableViews(延迟确实会损害性能),但是您可以(而且我确实)将其用于任何 Web 图像加载。这样可以保持 UI 流畅并且速度非常快。

于 2013-03-20T10:24:32.460 回答
0

嗨以这种方式创建网址

[NSURL URLWithString:[[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]

我认为它会起作用并且会解决你的问题。

于 2013-04-09T10:41:11.237 回答
0
NSMutableArray *imagename = [[NSMutableArray alloc] initWithObjects:@"http://4cing.com/mobile_app/uploads/pageicon/6.jpg", nil];
UIImageView *imgDescView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 200, 200)];

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                                            [NSURL URLWithString:[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]]]]];

它正在工作......我认为你没有正确创建数组。

于 2013-03-20T10:16:56.610 回答