2012-11-18 48 views
0

我有一个UITableView来自用JSON创建的数组,但我不知道如何从数组中显示图像。图像是一个字符串网址,但我不能在UITableView上显示它。从Json Array显示UITableView上的图像

我知道的代码来显示文本出下一码:

cell.textLabel.text = [[lista objectAtIndex:indexPath.row]objectForKey:@"title"]; 

,但我不能用它来与图片的网址,因为“形象”是一个字符串数据:

cell.imageView.image = [[lista objectAtIndex:indexPath.row] objectForKey:@"Images"]; 

如何显示URL中的图像?

谢谢

+1

所以,当你处理一个JSON时,我期待你的加载数据一台服务器和图像的字符串包含图像已存储的URL? – flashfabrixx

回答

0

您需要实际下载图像。

当你是一个初学者,我建议您下载并使用AFNetowrking

AFNetworking有一个简单的类来从URL下载UIImages:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; 
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]]; 

如果你是在一个泰伯维细胞,你简单的使用TableView的cellImageView,而不是创建一个新的UIImageView,如:

[cell.imageView setImageWithURL:[NSURL URLWithString:[[lista objectAtIndex:indexPath.row] objectForKey:@"Images"]] placeholderImage:[UIImage imageNamed:@"myplaceholderimage.png"]]; 
+0

ty,即将试用它! – Andres