2010-08-12 45 views

回答

2

這將阻止,使用NSURLConnection的對於非阻塞下載

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World"]]; 

UIImage *downloadedImage = [UIImage imageWithData:imageData]; 

myImageView.image = downloadedImage; 
+0

它與NSURLConnection ....工作....謝謝.... – Swapnil 2010-08-13 06:02:04

+0

高興地幫助:) – willcodejavaforfood 2010-08-13 08:23:12

0

嘗試imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:aURL]]

+0

我做了這個,但它不工作....謝謝你的回覆 – Swapnil 2010-08-12 12:06:34

0

@iSwap - 我知道爲什麼你的代碼是不工作。

我想你把一個網址作爲字符串而不是網址。 如上代碼----

imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:aURL]]; 

有aURL這應該是一個URL不是字符串,和u寫了它作爲一個字符串像

imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:@"http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World"]]; 

你已經忘了這個字符串轉換成一個網址。

正確的方法會像這個 -

imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World"]]]; 

我希望你得到它,還有一兩件事沒有「willcodejavaforfood」和「CodeBrickie」代碼之間沒有區別。只是寫作方式幾乎沒有什麼不同。