Hi
I am creating a custom UITableViewCell to include an image and some related text. I am getting the images from the Internet and while the images load, I display a temporary image.
I am using a separate thread to get the images. Once an image is downloaded, I am firing a method on the main thread to set the image in the UIImageView (getting the instance of image view using tags)
But whatever I do, the images are not changed. The cells still display older images (corresponding to different row - due to reusing of cells) and new images are not reflected. Log statements show that the method to set the image is being called.
I even tried changing the image to a static image in willDisplayCell:forRowAtIndexPath: but even then the image does not change.
Can someone please tell me what is happening here.
Thanks.
Edit
I tried calling reloadData on the tableview after changing the image, but the image still does not change.
Here's the relevant piece of code
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 which is called on the main thread after an image is downloaded
-(void)setImageInArray:(NSIndexPath *)indPath{
[filesTable reloadData];
}
In the thread, I am adding the image object to imagesArray. So when the next time the cellForRowAtIndex method is called on reloadData, the new image should be displayed.