ios – 在customCell中循环浏览uiimageview

你好,我有产品表和产品详细信息视图为每个产品我有很多图像,下载和缓存在磁盘和内存,每次用户选择一个产品,以检查其细节我正在检索缓存的图像,并设置为我的四UI ImageView在UITableViewController中的自定义单元格内,我无法设置图像,尽管我可以通过NSLog()函数记录它我正在使用此代码
int index = 0;
    int indexOfImages = 1;
    self.imageCache = [[SDImageCache alloc] initWithNamespace:@"menuImage"];
   for ( UIImageView *currentimageView in cell.contentView.subviews)
    {
        NSLog(@"the imageindex is: %d",indexOfImages);
        NSLog(@"the index is: %d",index);
        NSLog(@"the count is: %lu",(unsigned long)[self.currentProduct.mirsaProductUrlImage count]);
        if (index < [self.currentProduct.mirsaProductUrlImage count] ) {
             [self.imageCache querydiskCacheForKey:self.currentProduct.mirsaProductUrlImage[indexOfImages]  
    done:^(UIImage *image,SDImageCacheType cacheType) {
                if (image) {
                   currentimageView.image =  image;
                }
            }];
            indexOfImages++;
            index++;
         }
         else
        {
            break;
        }
    }

and if i try to change the loop way to this

for ( UIImageView *currentimageView in self.tableView.subViews)

i got this error UITableViewWrapperView setimage:]: unrecognized selector sent to instance

我只是想知道我是否以错误的方式循环,我的意思是我无法通过这个循环达到他们或发生了什么?

解决方法

你必须改变循环:
for ( UIView *currentView in cell.contentView.subviews)
   {
      if([currentView isKindOfClass:[UIImageView class]])
      {
           // here Do All the stuff for imageViews
      }
   }

做所有这些东西在cellForRowAtIndexPath
并改变imageView图像采取的弱视频imageView这样的例子:

__weak UIImageView *weakImage = currentimageView;
 [self.imageCache querydiskCacheForKey:self.currentProduct.mirsaProductUrlImage[indexOfImages]  
    done:^(UIImage *image,SDImageCacheType cacheType) {
                if (image) {
                    weakImage.image =  image;
                }
 }];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...