0

I fetched images from json and put all image url's in array, rather than calling json again. Now i don't know how to set the condition that it load images as table scrolled. Here is the method i called for this.

+ (NSMutableArray *) createImg: (NSArray*)sampleData
{
NSMutableArray *arrImg = [[NSMutableArray alloc]init];
for(int i=1; i<=[sampleData count]; i++)
{
NSString *strOfUrl = [sampleData objectAtIndex:i];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strOfUrl]]];
    if(img == NULL)
    {
        NSLog(@"null no image");
    }
    else{
        [arrImg addObject:img];
    }   
}
return arrImg;
}

Please guide for the above and feel free to ask anything if not clear in this. Thanks in advance.

iPhone Programmatically
  • 1,211
  • 2
  • 22
  • 54
  • Duplicate question http://stackoverflow.com/questions/1130089/lazy-load-images-in-uitableview – Tirth Mar 07 '13 at 09:43

2 Answers2

0

I know this might not be exactly what you are looking for. However, I'd suggest you to use this AsyncImageView. It'll do all the logic you need for lazy loading. Also, it'll cache the images. To call this API:

ASyncImage *img_EventImag = alloc with frame;
NSURL *url = yourPhotoPath;
[img_EventImage loadImageFromURL:photoPath];
[self.view addSubView:img_EventImage];  // In your case you'll add in your TableViewCell.

It's same as using UIImageView. Easy and it does most of the things for you. AsyncImageView includes both a simple category on UIImageView for loading and displaying images asynchronously on iOS so that they do not lock up the UI, and a UIImageView subclass for more advanced features. AsyncImageView works with URLs so it can be used with either local or remote files.

Loaded/downloaded images are cached in memory and are automatically cleaned up in the event of a memory warning. The AsyncImageView operates independently of the UIImage cache, but by default any images located in the root of the application bundle will be stored in the UIImage cache instead, avoiding any duplication of cached images.

The library can also be used to load and cache images independently of a UIImageView as it provides direct access to the underlying loading and caching classes.

Rushi
  • 4,553
  • 4
  • 33
  • 46
  • can you tell exactly what to write in cellforrwoatindexpath method. – iPhone Programmatically Mar 07 '13 at 09:54
  • ASyncImage *img_EventImag = alloc with frame; NSURL *url = yourPhotoPath; [img_EventImage loadImageFromURL:photoPath]; [self.view addSubView:img_EventImage]; This you'll have to write in cellforrwoatindexpath. But before that you'll need to add the required files to your project. – Rushi Mar 07 '13 at 09:56
0

use this. It is perfect way to show images while scrolling: https://github.com/enormego/EGOImageLoading

Saurabh Singh
  • 247
  • 1
  • 6