1

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

Vidya Vasudev
  • 81
  • 2
  • 5
  • 1
    Create the needed UIImageView's for your cell and use https://github.com/rs/SDWebImage for async downloading of images. – Praveen S Jun 12 '13 at 10:52

3 Answers3

2

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.

Community
  • 1
  • 1
Divyu
  • 1,325
  • 9
  • 21
  • There is an option available NSURLCacheStorageNotAllowed in AFNetworking. Check that. – Divyu Jun 12 '13 at 11:09
  • your ans explicitly implies AFNetworking does not use cacheing..which i pointed out as far as checking out is concerned i have done many tweaks in it to disable and enable caching to show updated images etc.. – amar Jun 12 '13 at 11:11
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

Sravan
  • 1,891
  • 4
  • 23
  • 28
  • @Vidya Vasudev: did my post help ? – Sravan Jun 18 '13 at 17:40
  • Better than SDWebImage. No weird fit when loaded image doesn't have the same aspect ratio with the placeholder. 0 dependencies. And I don't really need caching, I just need a solution that doesn't lock up the app while images are loading. Thanks! – marko Oct 11 '14 at 19:11
0

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

user133
  • 88
  • 6