Sunday, 29 September 2013

AFNetworking success block ReusableCell

AFNetworking success block ReusableCell

I need to save downloaded Images to the device, so I'm using AFNetworking's
setImageWithURLRequest:placeholderImage:success:failure:
But this sets set's the image in the wrong cell's imageview when I scroll
the table.
What is the correct way to use this method for reusable tableview cells?
This is how I'm using it:
NSURL *nsurl = [NSURL URLWithString:[kBaseURL stringByAppendingString:
remoteImagePath]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsurl];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
UIImageView *imgView = imageView;
[imageView setImageWithURLRequest: request
placeholderImage: placeholderImage
success: ^(NSURLRequest *request,
NSHTTPURLResponse *response, UIImage *image) {
imgView.image = image;
NSString *imageName = [[localImagePath
componentsSeparatedByString:@"/"]
lastObject];
[self saveInCacheDirImage:image
withName:imageName];
}
failure: nil
];

No comments:

Post a Comment