我正在iPhone應用程序中使用谷歌圖表功能....我想下載圖像並將其從http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World ... 有沒有任何示例應用程序做這種功能?或任何其他方式來顯示應用程序中的圖表?從iPhone應用程序的URL下載圖像
在此先感謝...
我正在iPhone應用程序中使用谷歌圖表功能....我想下載圖像並將其從http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World ... 有沒有任何示例應用程序做這種功能?或任何其他方式來顯示應用程序中的圖表?從iPhone應用程序的URL下載圖像
在此先感謝...
這將阻止,使用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;
嘗試imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:aURL]]
我做了這個,但它不工作....謝謝你的回覆 – Swapnil 2010-08-12 12:06:34
@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」代碼之間沒有區別。只是寫作方式幾乎沒有什麼不同。
它與NSURLConnection ....工作....謝謝.... – Swapnil 2010-08-13 06:02:04
高興地幫助:) – willcodejavaforfood 2010-08-13 08:23:12