下载多个图像并显示多个UIImageView的最佳方法是什么? [英] What's the best way to download multiple images and display multiple UIImageView?

查看:107
本文介绍了下载多个图像并显示多个UIImageView的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从网站下载图像并在(?)多个UIImageView上显示它们。

I need to download images from a website and display them on(?) multiple UIImageView.

也许我会编写一个php来读取目录和搜索图像,编写XML文件并将其用作媒介。但我不确定这是不是最好的方式。

Maybe I'll code a php to "read" the directory and search for images, write a XML file and use it as medium. But I'm not sure if it's the best way.

推荐答案

让我们看一下从网站上获取图片的选项:

Let's see the options you have to fetch images from a website:


  1. 获取HTML并解析HTML以查找图像(在iPhone上)。然后下载图像。

  1. Fetching HTML and Parsing the HTML to find the images (on the iphone). Then downloading the images.

编写一个脚本(可能是PHP),将所有图像链接写入XML文件(或JSON),然后获取输出包含所有链接的脚本。

Writing a script (maybe PHP) that writes all image links to an XML file (or JSON), and then fetch the output of your script with all the links.

如果选择选项(1),则需要 NSURLConnection 以异步方式获取数据(无阻止UI)。我还会使用 TFHpple 来使用xpath查询来解析HTML,请参阅这个教程寻求帮​​助。最后,使用他们的URL获取图像,您可以使用 SDWebImage ,SDWebimage还提供缓存,以便您的应用程序无法下载多次使用相同的图像。

If you choose option (1) you'll need NSURLConnection to fetch data asynchronously (without blocking the UI). I would also use TFHpple to parse HTML using xpath queries, see this tutorial for help. Finally to fetch the images using their URLs you can use SDWebImage, SDWebimage also provides caching so your app will not download the same image multiple times.

使用选项(1)的不好的一面是,您从中获取图像的网站的任何更改都将破坏您的应用程序和您我需要向应用程序商店发布更新才能修复它。

The bad side of using option (1) is that any change in the Website you're getting the images from will break your app and you'll need to issue an update to the app store in order to fix it.

如果选择选项(2),如果您的网站更容易修复更改,你只需要修改你的脚本。

If you choose option (2), your app will be easier to fix if the website changes, you'll just need to modify your script.

如果你选择选项(2)你可能需要 NSURLConnection NSXMLParser (或第三方XML解析库)并下载图像,我将再次推荐 SDWebImage 。我还建议使用JSON(和 NSJSONSerialization )而不是XML,因为我发现JSON更容易解析。

If you go with option (2) you'll probably need NSURLConnection, NSXMLParser (or a third party XML parsing library) and to download the images I would recomend SDWebImage again. I would also advise using JSON (and NSJSONSerialization) instead of XML, just beacuse I find JSON easier to parse.

这篇关于下载多个图像并显示多个UIImageView的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆