延迟加载UITableView,每个单元格中有多个图像

时间:2013-06-12 10:48:55

标签: iphone ios uitableview lazy-loading

我正在使用延迟加载在表格视图上显示图像。 但是我需要在每个单元格中创建一个包含多个图像的tableview。它可以滚动。 所有图像仅从服务器加载 如何创建这个没有任何滞后的表滚动? 有没有可用的教程

3 个答案:

答案 0 :(得分:2)

试试这段代码。 SDWebImage。它从服务器下载图像并将其保存到设备缓存。 此外,如果您不想将其保存到缓存中,那么您可以查看AFNetworking

答案 1 :(得分:2)

还有另一种选择。使用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的性能。

请参阅this以了解有关GCD

的更多信息

答案 2 :(得分:0)

试试这个https://github.com/nicklockwood/AsyncImageView。很容易从服务器异步下载图像。

相关问题