iOS - 在Objective C中从Web服务器加载图像 [英] iOS - Loading an image from a web server in Objective C

查看:130
本文介绍了iOS - 在Objective C中从Web服务器加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的目标是编写包含UIImageView的应用程序。加载或按下按钮后,来自Web服务器的图像将加载到视图中。

At the moment, I have a goal of writing an application that contains a UIImageView. Upon loading or pressing a button, an image from a web server will load into the view.

最简单的方法是什么?我假设使用此处描述的API? https://developer.apple.com/ library / mac / #documentation / Cocoa / Conceptual / URLLoadingSystem / Tasks / UsingNSURLConnection.html

What is the simplest way to do this? I'm assuming using the API described here? https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

同时,我会继续尝试这个独自工作。任何建议都会受到赞赏,特别是如果您之前已经编写了这样的代码。

In the mean time, I will continue to try to get this working on my own. Any advice would be appreciated, especially if you have written code like this before.

推荐答案

是的,这可以通过制作一个通过NSURLConnection请求。

Yes, this can be done by making a request through an NSURLConnection.

您可能有兴趣查看 SDWebImage 。此库包含一个类别,该类别向 UIImageView 添加一个方法,该方法从远程URL异步加载图像,如下所示:

You might be interested in checking out SDWebImage. This library includes a category that adds a method to UIImageView that makes asynchronously loading an image from a remote URL as simple as this:

[self.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

这篇关于iOS - 在Objective C中从Web服务器加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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