2014-09-30 101 views
0

如何在從WebService獲取的ImageView中顯示圖像?從WebService獲取的顯示圖像

我能夠成功地檢索從服務形象的名稱,但不能設置在圖像中的ImageView

NSString *imgName = [students objectForKey:@"Image"]; 
NSLog(@"%@", imgName); **/* Image1.png */** 
imgImage.image = [UIImage imageNamed:imgName]; 

的NSLog給出下面的控制檯輸出:

此搜索。 PNG

我無法設置圖像中的ImageView

+0

你有這個名稱圖像添加到您的項目? – Anuj 2014-09-30 09:55:37

+0

您必須檢查該圖像是否已添加到目標 – Anuj 2014-09-30 09:56:48

+0

'imgImage.image = [UIImage imageNamed:imgName];' 此語句只會顯示圖像,如果它已添加到項目中。我認爲該圖片尚未下載到您的設備上。所以可能是圖像將被提取像這樣http://stackoverflow.com/questions/17318471/loading-images-in-background-to-optimize-the-loading-in-ios/17318655#17318655 – Dinesh 2014-09-30 09:58:31

回答

2

您可以使用SDWebImage:

// Here we use the new provided setImageWithURL: method to load the web image 
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] 
       placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

這是鏈接下載以及如何使用它: https://github.com/rs/SDWebImage

+0

我的網址收到JSON字符串 – 2014-09-30 10:58:42

+0

您應該收到格式爲http://example.com/image1.png的完整網址,或者您應該通過將基本網址附加到您的網址來構成洞鏈接imgName string: NSString * imgName = [NSString stringWithFormat:@「%@%@」,baseURL,[students objectForKey:@「Image」]] – 2014-09-30 11:06:20

1

您也可以使用此代碼集圖像

cell.img.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"your url"]]]]; 
相關問題