延迟加载UITableView,每个单元格中有多个图像 [英] Lazy loading UITableView with multiple images in each cell

查看:87
本文介绍了延迟加载UITableView,每个单元格中有多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用延迟加载在表格视图上显示图像。
但是我需要在每个单元格中创建一个包含多个图像的tableview。它可以滚动。
所有图像都是从服务器加载的
如何在不滚动表格滚动的情况下创建它?
是否有可用于此的教程

I am using lazy loading to show images on a table view. But I need to create a tableview with multiple images in every cell.Which can be scrolled. All images are loaded from server only How can I create this without any lagging for table scrolling ? Is there any tutorial available for this

推荐答案

还有另一种选择。使用 GCD(Grand Central Dispatch)

There is another option. Using GCD (Grand Central Dispatch).

示例代码:

// Get the filename to load.
    NSString *imageFilename = [imageArray objectAtIndex:[indexPath row]];
    NSString *imagePath = [imageFolder stringByAppendingPathComponent:imageFilename];

    [[cell textLabel] setText:imageFilename];

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

    dispatch_async(queue, ^{
        UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

        dispatch_sync(dispatch_get_main_queue(), ^{
            [[cell imageView] setImage:image];
            [cell setNeedsLayout];
        });
    });

使用相同的方式显示多个图像。使用它会增加加载tableview的性能。

Use the same for showing multiple images. Using this will increase the performance of loading tableview definitely.

参考 this 了解更多关于 GCD

这篇关于延迟加载UITableView,每个单元格中有多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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