Lazy loading UITableView with multiple images in each cell

a 夏天 提交于 2019-11-28 06:17:00

问题


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


回答1:


Try this code. SDWebImage. It downloads image from server and save it to device cache. Also if you don't want save it to cache then you might have a look at AFNetworking.




回答2:


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

Example Code :

// 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];
        });
    });

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

Refer this to know more about GCD




回答3:


Try this https://github.com/nicklockwood/AsyncImageView .Easy to download images asyncronously from server.



来源:https://stackoverflow.com/questions/17063580/lazy-loading-uitableview-with-multiple-images-in-each-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!