Lazy load images in UITableView

Try AFNetworking class download this class in this link https://github.com/AFNetworking/AFNetworking . Add the all AFNetworking class in your project.Then just import this category

#import "UIImageView+AFNetworking.h" in your Viewcontroller which contains your Tableview.

Then in cellForRowAtIndexPath: put like below

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    if (cell == nil) 
    {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }

    [cell.imageView setImageWithURL:[NSURL URLWithString:[UrlArray objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@"placeholder.jpg"]];
     cell.myLabel.text = [imageNameArray objectAtIndex:indexPath.row];

     cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;    
}

This download your Image for imageView in the UITableviewcell asynchronously. It wont download again and again while the user scroll the Tableview, because it has cache also. Once your image download it save the image with key of your imageUrl. I hope it useful for you.

Leave a Comment