下载多个图像并显示多个UIImageView的最佳方法是什么?

时间:2020-12-18 18:11:11

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

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

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.

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

2 个解决方案

#1


1  

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

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

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

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

  2. 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.

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

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),则需要NSURLConnection异步获取数据(不阻止UI)。我还将使用TFHpple使用xpath查询解析HTML,请参阅本教程以获取帮助。最后,使用他们的URL获取图像,您可以使用SDWebImage,SDWebimage还提供缓存,因此您的应用程序不会多次下载相同的图像。

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.

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

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),如果网站发生变化,您的应用将更容易修复,您只需修改脚本即可。

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.

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

#2


0  

Yes, it will be very good if you write some php script to get image list (list of image urls). After getting such urls you can asynchronously download and show them in image views. Look here for such async image view implementation

是的,如果您编写一些PHP脚本来获取图像列表(图像URL列表),那将是非常好的。获得此类网址后,您可以异步下载并在图像视图中显示它们。在这里查看这样的异步图像视图实现

#1


1  

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

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

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

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

  2. 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.

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

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),则需要NSURLConnection异步获取数据(不阻止UI)。我还将使用TFHpple使用xpath查询解析HTML,请参阅本教程以获取帮助。最后,使用他们的URL获取图像,您可以使用SDWebImage,SDWebimage还提供缓存,因此您的应用程序不会多次下载相同的图像。

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.

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

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),如果网站发生变化,您的应用将更容易修复,您只需修改脚本即可。

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.

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

#2


0  

Yes, it will be very good if you write some php script to get image list (list of image urls). After getting such urls you can asynchronously download and show them in image views. Look here for such async image view implementation

是的,如果您编写一些PHP脚本来获取图像列表(图像URL列表),那将是非常好的。获得此类网址后,您可以异步下载并在图像视图中显示它们。在这里查看这样的异步图像视图实现