Lazy Loading image Download

Lazy loading is a key thing when you are working on some application where you interact with server side and download data from server side. Normally when we use to download images from server then it takes more time than textual data and users don’t like to wait anywhere. So today I decided to share a good thing with you guys. This article is using some Model Classes which are copy right of “james https://github.com/mystcolor” (c) Olivier Poitrey . So lets start Step by Step

1. Create a new Project

2. Add a UITableView in your view controller or make a Controller inherited by UITableViewController

3. Create an array in your .h class

4. Assign all the image paths to that Array

5. Create a custom Cell or generate it on run time

6. Add Model classes of james

7. Get a URL

8. Make its image and assign to your UIImageView

All these are simple steps. What you want to make something extra is to add a new line and add some Model Classes LazyLoadingModels

Now add

1
#import “UIImageView+WebCache.h”
file into your Custom cell class or wherever you are going to assign image to your UIImageView

now assign image to your UIIMageView in this way

1
2
3
NSURL *url = [NSURL URLWithString:_lbl2];

[self.photoImageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@”backImage.png”]];
instead of

1
[self.photoImageView setImageWithURL:url];
Now you are good to go ahead. Source Code is available here LazayImageLoading

Thanks for reading

Happy Coding and MindYourCode 🙂

About Qasim Masud

Leave a Reply