客观c。在一次多个异步请求 [英] Multiple async requests at once in objective c

查看:101
本文介绍了客观c。在一次多个异步请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一时间下载我从Web服务器多张图片,我的问题是,他们混淆了对方。

I have am downloading multiple images from a web server at the same time, and I the problem is they are getting mixed up with each other.

dispatch_async(dispatch_get_global_queue(0,0), ^{
    NSData * data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"website.com"]];
    if (data == nil)
        return;
    dispatch_async(dispatch_get_main_queue(), ^{
        cell.imageView.image = [UIImage imageWithData:data];
    });
});

我得到这个code来源:获取图像从URL目标C

我要如何解决这个问题?也就是有什么办法可以加快下载速度?

How do i fix this?? also is there any way to speed up download speeds?

推荐答案

您可以使用AsyncImageView类文件会同步加载图片,它显示了活动的指标,而图像加载

You can use "AsyncImageView" class files it will load image synchronously and it shows the activity indicator while image loading

AsyncImageView是类文件,在其中它将为每一个呼叫与图像数据下载完成,它将返回图像ImageView的连接。如果图像已经在缓存中,然后直接返回图像而无需创建连接。

AsyncImageView is the class file in which it will create connection for each call and when image data downloading completed it will return image for imageview. and if image is already in cache then just return image without creating connection.

您可以下载AsyncImageView类文件: - 的https:// WWW .dropbox.com / S / peazwjvky9fsjd7 / Archive.zip

You can download "AsyncImageView" class files from following link:- https://www.dropbox.com/s/peazwjvky9fsjd7/Archive.zip

在.m文件导入AsyncImageView类

in .m file import AsyncImageView Class

  #import "AsyncImageView.h" 

在indexpath方法您的tableview细胞

in your tableview cell at indexpath method

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifier = @"SimpleTableCell";
     UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

     UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(X, y, width, height)];

     NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"];
     AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    [async loadImageFromURL:[NSURL URLWithString:imageURL]];
    [imageView addSubview:async];
    [cell addSubview:imageView];
    return cell;
}

试试这个您的问题将解决。

try this your problem will solve.

这篇关于客观c。在一次多个异步请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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