开发者

how to download photos from remote server to iphone app?

My situation is that I am making a uitableviewcontroller with uitableviewcells having a thumb nail or pictur开发者_运维知识库e on the left, text on the right. All data is stored in a remote server. I have made a php to communicate with backend batabase and generate JSON to pass the data to iphone through http. However, I don't know how to do the same thing to photos. Please suggest me someway to do it. Thanks!


As Mundi said it already.

And make sure that you load them asynchronously.

There is a nice tutorial on this page: http://www.markj.net/iphone-asynchronous-table-image/


I assume you are using NSURLConnection to fetch your data from the server. Do this:

Collect the photo data into an NSData object.
In the didFinishLoading method use this to create the images:

UIImage *thumbnailImage = [[UIImage alloc] initWithData:downloadedData];
// don't forget to discard the downloaded Data and release the image

The actual setup of your cells might be more complicated. The way I do it is to check in each call to cellForRowAtIndexPath: if I have cached the image, if not I pass to URL of the image to a NSURLConnection. I keep the open connections in an array and eliminated them when each download finishes or the view disappears. Let me know if you need more hints...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜