sri
sri

Reputation: 3379

Lazy image download using NSBlockOperation and NSOperationQueue in iOS

I'm trying to show image and text using tableview in my app , for lazy image download, I'm using NSBlockOperation and NSOPerationQueue to image download. So that all the image request will be added into the queue and concurrently image downloaded will be initiated. It is working fine when landed to that page if you wait few minutes to all the image download. App get crashed if as soon as come to this screen and go back to previous screen. I could understand the problem is that screen no longer there. Help me! How would I fix the issue?

Appreciate your help!!

Sri

Upvotes: 1

Views: 899

Answers (3)

E-Riddie
E-Riddie

Reputation: 14780

Solution is using this library and which doesn't need you to set up downloading it, the library handles itself - SDWebImage

You just need to #import <SDWebImage/UIImageView+WebCache.h> to your project, and you can define also the placeholder when image is being downloaded with just this code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *CellIdentifier;
        CustomCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        MyObject *object = (MyObject *)[self.list.array objectAtIndex:indexPath.row];

        [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                       placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

        return cell;
}

It also cache downloaded images and gives you great performance.

Upvotes: 0

mangesh
mangesh

Reputation: 574

if you want to download the image asynchronously then please have a look at this repository on github and also refer this blog hope that will solve your problem. For crash put some code.

Upvotes: 1

Ranjit
Ranjit

Reputation: 4636

Refer this for lazy Image loading as recommended by Apple

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

Upvotes: 0

Related Questions