It seems that your issue is related to cell reusing rather to the caching issue.
When your cells are reused (when scrolling the UITableView
or reopening the app) they hold a reference to the old image. And when you pass nil
to the placeholderImage
parameter, AFNetworking does not resets your image. Here is the source code. So the new image is set in a success
block. But this block may be called after a slight network delay making your image to flash. By the way, you may omit the success block so the AFNetworking will set the image by itself.
If you don't have a placeHolder image you should set the myImageView.image
to nil
before trying to set a new one asynchronously.
In addition you should check if the dequeueReusableCellWithIdentifier:
method returns a cell, and if not, create a new one. This may happen when the UITableView
is created for the first time.
Here is an example:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
myCell *cell = (myCell *)[tableView dequeueReusableCellWithIdentifier:@"imageCell"];
// Check if reused cell was returned.
// If not create a new one, otherwise, reset the state of the reused cell
if (!cell) {
cell = [[myCell alloc] init];
} else {
cell.myImageView.image = nil;
}
[cell.myImageView
setImageWithURLRequest:[NSURLRequest requestWithURL:myImageUrl]
placeholderImage:nil
success:nil
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Failed");
}];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}