xcode iOS - 异步图片下载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9789009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:43:06  来源:igfitidea点击:

iOS - Asynchronous Image Downloading

objective-ciosxcodeimageasynchronous

提问by Ashley Staggs

I am writing an app which is going to be displaying images found on my server in a UIImageView.

我正在编写一个应用程序,它将在 UIImageView 中显示在我的服务器上找到的图像。

I need something that will asynchronously download the image and cache it while putting it in the UIImageView. The download also needs to be able to be cancelled when I press a button.

我需要一些可以异步下载图像并在将其放入 UIImageView 时缓存它的东西。当我按下按钮时,还需要能够取消下载。

Can anyone point me in the direction of something that can do this?

任何人都可以指出我可以做到这一点的方向吗?

回答by LuisEspinoza

In the old times the framework for that was ASIHTTPRequest but is an abandoned project now. This https://github.com/AFNetworking/AFNetworkingseems to be popular now.

在过去,它的框架是 ASIHTTPRequest,但现在是一个废弃的项目。这个https://github.com/AFNetworking/AFNetworking现在好像很流行。

回答by matzino

Use the performSelectorInBackground:withObject: - method from NSObject ;)

使用 performSelectorInBackground:withObject: - 来自 NSObject 的方法;)

Advise: The updating of the view must run on the main thread!

忠告:视图的更新必须在主线程上运行!

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html