ios - 如何在 UItableview customcell 中从 url 加载两个图像

标签 ios uitableview

在我的应用程序中,我使用自定义 tableviewcell 在一个单元格中加载两个图像,我的问题是当我第一次在我的 View 中加载该图像时,它显示交换图像(第二个图像中的第一个图像和第一个图像中的第二个图像)和然后在几分之一秒后加载正确的图像(第一张图片中的第一张和第二张图片中的第二张图片)。我正在使用 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]];

最佳答案

我遇到过这类问题,我使用过 SDWebImage.frameword。 这个框架集成非常简单,它会正确加载图像。

为此,我们首先需要创建 UIImageView 来代替 AsyncImageView。

使用以下代码在单元格中显示图像:

   [mMainImgView setImageWithURL:[NSURL URLWithString:loImgurl] placeholderImage:[UIImage imageNamed:@"placeholder"]];

有关其余详细信息,请查看 https://github.com/rs/SDWebImage

关于ios - 如何在 UItableview customcell 中从 url 加载两个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22980737/

相关文章:

objective-c - 如何在 tableView 单元格中显示多行

arrays - 在 swift 4.2 的 TableView 中重复数组的 n 索引

ios - UITableView 类型不符合 IntervalType 协议(protocol)

ios - 在 iOS 表格中显示响应图像和标签

ios - NSFetch请求 : Return dictionary with nested arrays of dictionaries

iphone - sqlite 随机文件已加密或不是数据库

ios - 格式化 JSON 接收到的字符串

swift - 从 tableview 内的 uicollectionview 继续

ios - 使用自动布局将 subview 的宽度与其父 View 匹配

ios - Flutter与iOS原生页面相互跳转