我在NSDictionary中有图像路径,就像(带键:image_path)
[productDictionary objectForKey:@“image_path”];
我可以在相同字典的标签上设置文本 喜欢
cell.lbl.text = [productDictionary objectForKey:@“somestatus”];
但不知道如何为图像做同样的事情(在UIImageview上设置)。
如何在UIImageview上设置它? 而不是这个:
cell.imgvQuotes.image = [UIImage imageNamed:@“static.png”];
我想从字典中设置图像而不是“static.png”
解析后我有一个图像的URL,就像
http://google.com/images/noimage.png //无效,只是一个例子
答案 0 :(得分:4)
您可以使用:
id imageName = [productDictionary objectForKey:@"image_path"];
cell.imgvQuotes.image = [UIImage imageNamed:imageName];
答案 1 :(得分:1)
您可以使用相同的方法,而是从字典中获取图像名称,如下所示:
cell.imgvQuotes.image = [UIImage imageNamed:[productDictionary objectForKey:@"image_path"]];
答案 2 :(得分:0)
如果词典包含图像名称而不是imagePath,则@Adil的上述答案是正确的。
如果字典包含您在问题(URL)中提到的路径
cell.imgvQuotes.image = [UIImage imageWithContentsOfFile:[productDictionary objectForKey:@“image_path”]];