在UITableViewView中下载异步多个图像? [英] Download an asynchronous multiple images in UITableViewView?

查看:79
本文介绍了在UITableViewView中下载异步多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ASIHttpRequest或其他有用的东西在UITableView中下载异步多个图像?

How can i download an asynchronous multiple images in the UITableView using ASIHttpRequest or something useful?

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
      ..........

      // Creation
      UIImageView *avatar;
      UILabel *content; 

      // Tag the IBOutlets
      avatar = (UIImageView*)[cell viewWithTag:14];
      content = (UILabel*)[cell.contentView viewWithTag:4];

      // Field
      avatar.image = image
      content.text = entryReviewtableView.content;
 }


推荐答案

无需引入依赖项到ASIHTTPRequest这样的整个框架只是为了下载一个图像,当你可以使用GCD做几行简单的代码时:

No need to introduce a dependency to a whole framework such as ASIHTTPRequest just to download one image, when you can do it a few easy lines of code using GCD:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *imageDate = [NSData dataWithContentsOfURL:imageURL];
    UIImage *image = [UIImage imageWithData:imageData];
    dispatch_async(dispatch_get_main_queue(), ^{
        avatar.image = image;
    });
});

这是异步的,所有的善良。但是在几行代码中,您可以编写,理解,修复错误,扩展和维护自己。

This is asynchronous and all the goodness. But in a few lines of code you can write, understand, bug-fix, extend and maintain yourself.

这篇关于在UITableViewView中下载异步多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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