0

I have a tableview with each cell having its own imageview. I'm using AsyncImageView to load images from the internet into the imageview. Certain imageviews seem to be loading a repeated image into different cells:

enter image description here

In the screenshot above, Image B loads twice when it's not supposed to. This happens quite often as I scroll up and down. When this happens I scroll away and scroll back to the cell and the correct image is loaded. Later when I scroll back again, the same problem happens. I'm not able to trace where the problem is coming from. Anyone have any ideas?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   
{
    static NSString *simpleTableIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleTableIdentifier owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }else
    {
        [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.logoImageView];
        cell.logoImageView.image = nil;
    }

    //Cause sections
    NSMutableArray *tempArray = [self.sectionArray objectAtIndex:indexPath.section];
    MyObject *myObject = [tempArray objectAtIndex:indexPath.row];

    NSString *thumbUrlString = [myObject valueForKey:@"thumbUrl"];

    if([thumbUrlString length]>0 )
    {
        NSString *imageUrl= [NSString stringWithFormat:@"http://www.sitename.com/%@",thumbUrlString];
        NSURL *url = [NSURL URLWithString:imageUrl];
        cell.logoImageView.imageURL=url;
    }else{
        cell.logoImageView.image = [UIImage imageNamed:@"placeholder.png"];
    }

    return cell;
}
Carl Anderson
  • 3,446
  • 1
  • 25
  • 45
Moo33
  • 1,251
  • 3
  • 15
  • 27

2 Answers2

0

I suppose that when you set cell.logoImageView.imageURL you then call something like [AsyncImageLoader sharedLoader] loadImageAtURL:logoImageView.imageURL] inside your CustomCell code or similar.

Probably you are using the same shared AsyncImageLoader for all the images, so every time you ask for a new image you overwrite the previous image request, or you are create different threads for every request by they are returning their results to the wrong cell.

Please post some code of your AsyncImageLoader.

Alberto Malagoli
  • 1,173
  • 10
  • 14
  • Hi albermala. I have nothing in my CustomCell code wise, just a nib file. I was under the impression AsyncImageView handles requests in tableviews according to their demo: https://github.com/nicklockwood/AsyncImageView/blob/master/Examples/Basic%20Example/AsyncImageDemo/ImagesViewController.m What you said sounds plausible. Do I therefore have to create different instances of AsyncImageLoader? – Moo33 Dec 19 '14 at 03:11
  • @Moo33 Have you found the problem? If so, mark your answer as the correct one, otherwise we'll keep talking about AsyncImageLoader... – Alberto Malagoli Dec 19 '14 at 08:40
0

Made a silly mistake with:

 cell.logoImageView.image = nil 

Changed it to:

cell.logoImageView.imageURL = nil 
Moo33
  • 1,251
  • 3
  • 15
  • 27