I use UIImageView+MKNetworkKitAdditions in MKNetworkKit to show image from network, but when the UIImageView is in the tableView Cell, the method
-(MKNetworkOperation*) setImageFromURL:(NSURL*) url
placeHolderImage:(UIImage*) image
animation:(BOOL) yesOrNo;
won't show the image immediately after the image is downloaded. If I use
[tableView reloadData]
I won't see the animation of showing image. So I'm wondering how I can solve this problem. Thank you.
My codes are here
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.imageView setImageFromURL:[NSURL URLWithString:@"https://www.google.com/images/srpr/logo11w.png"]];
return cell;
}
The issue is that UITableViewCell
has very optimised drawing and when this method is called there is no image in the imageView so the cell assumes that it is not required to render an image.
Now when the network request completes it will set the image but it is not asking the cell to redraw so you will see nothing.
You need to use a method that has a completion block and then ask the cell to reload when the image request has completed.