UIImageView inside UITableViewCell not updating
I am creating a custom UITableViewCell
one to include UIImageView
and some related text. I am getting images from the internet and when uploading images I am showing the temp UIImage
.
I am using a separate thread to get UIImage
. Once loaded, UIImage
I run a method on the main thread to set the image to UIImageView
(getting an instance UIImageView
using tags)
But no matter what I did, the images did not change. Cells still display old images (corresponding to different rows - due to reuse of cells) and new images are not reflected. The log statements show that the image set method is called.
I even tried changing the image to a static image in willDisplayCell:forRowAtIndexPath:
but even then the image doesn't change.
<i> Modifying>
I tried calling reloadData
on UITableView
after changing UIImage
but UIImage
still doesn't change.
Here's the relevant code snippet
cellForRowAtIndexPath
image = [imagesArray valueForKey:[NSString stringWithFormat:@"%i",indexPath.row]];
if(image == nil){
//display temporary images. When scrolling stops, detach new thread to get images for rows visible
NSString *pth = [[NSBundle mainBundle] pathForResource:@"folder" ofType:@"png"];
image = [UIImage imageWithContentsOfFile:pth];
[imgView setImage:image];
}
else{
[imgView setImage:image];
}
Method that is called on the main thread after the image is loaded
-(void)setImageInArray:(NSIndexPath *)indPath{
[filesTable reloadData];
}
On a stream, I add an object UIImage
to imagesArray
. Therefore, the next time the cellForRowAtIndex
method is called reloadData
, the new one should be displayed UIImage
.
source to share