在我的应用程序中,我使用自定义tableviewcell在一个单元格中加载两个图像,我的问题是当我第一次在我的视图上加载图像时,它显示了交换图像(第二张图像中的第一张图像和第一张图像中的第二张图像)然后在几分之一秒后加载适当的图像(第1张第1张和第2张图片第2张)。我正在使用AsyncImageView类来显示图像。每次第一次查看加载它显示错误,然后每次都正确。请帮帮我。
在CellForRow
AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:celllookAlik.btnFullImg.frame];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.tag = IMAGE_VIEW_TAG1;
[celllookAlik addSubview:imageView];
AsyncImageView *imageViewll = [[AsyncImageView alloc] initWithFrame:celllookAlik.lookAlikeImage.frame];
imageViewll.contentMode = UIViewContentModeScaleAspectFill;
imageViewll.clipsToBounds = YES;
imageViewll.tag = IMAGE_VIEW_TAG2;
[celllookAlik addSubview:imageViewll];
使用以下代码在单元格中显示图片:
NSString * imageImage = @"";
imageImage = [[self.arrayResponseLookAlike objectAtIndex:indexPath.row] objectForKey:@"ImagePath"];
AsyncImageView *imageViewCelebrity = (AsyncImageView *)[celllookAlik viewWithTag:IMAGE_VIEW_TAG1];
//cancel loading previous image for cell
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageViewCelebrity];
//load the image
imageViewCelebrity.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",imageImage]];
NSString * imageImageceleb = @"";
imageImageceleb = [[self.arrayResponseLookAlike objectAtIndex:indexPath.row ] objectForKey:@"LookLikeImage"];
AsyncImageView *imageViewllTemp = (AsyncImageView *)[celllookAlik viewWithTag:IMAGE_VIEW_TAG2];
//cancel loading previous image for cell
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageViewllTemp];
//load the image
imageViewll.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",imageImageceleb]];
答案 0 :(得分:1)
我遇到过这类问题,我使用过SDWebImage.frameword。 这种框架集成非常简单,它可以正确加载图像。
首先,我们需要创建UIImageView来代替AsyncImageView。
使用以下代码在单元格中显示图片:
[mMainImgView setImageWithURL:[NSURL URLWithString:loImgurl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
有关剩余详情,请查看https://github.com/rs/SDWebImage