提高速度 - 来自 NSURL 的 UIImage

发布于 2024-09-30 05:31:51 字数 503 浏览 0 评论 0原文

我使用以下代码来获取一些图像,这些图像将进入表格视图。但获取 30 张图像需要很长时间(5-6 秒)。

是否有更智能/更快的方法来做到这一点?

NSString *imageUrl = ......;
NSString *urlStr = 
[imageUrl UrlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[NSString alloc] initWithFormat:@"http://xxx.dk/xml.aspx%@", urlStr]; 
NSURL *url = [NSURL URLWithString:path];


NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
return img;
[..... release];

I'm using the following code to fetch some images, that are going into a tableview. But it takes ages (5-6 seconds) to get the 30 images in.

Is there a smarter/faster way to do this?

NSString *imageUrl = ......;
NSString *urlStr = 
[imageUrl UrlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[NSString alloc] initWithFormat:@"http://xxx.dk/xml.aspx%@", urlStr]; 
NSURL *url = [NSURL URLWithString:path];


NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
return img;
[..... release];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏日浅笑〃 2024-10-07 05:31:51

这里 profileimg 是从 Api 获取的,String name

NSString *profileimg=[Check objectForKey:@"IMAGE"];

imageview.image=[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profileimg]]];

Here profileimg is an get from Api ,String name

NSString *profileimg=[Check objectForKey:@"IMAGE"];

imageview.image=[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profileimg]]];
落日海湾 2024-10-07 05:31:51

我宁愿在屏幕上出现单元格时下载图像数组中的每个新图像,如果单元格第二次出现在屏幕上(即该单元格的图像已被下载),则仅显示已保存的图像。

I'd rather download every new image in array of images when a cell appears on the screen and just display already saved image if a cell appears on the screen for the second time (i.e. image for this cell has been already downloaded).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文