通过Customcell中的UIImageView循环



您好,我有每个产品的产品表和产品详细信息视图,我有许多图像在磁盘和内存上下载并在每次用户选择一个产品以检查其详细信息我正在尝试的详细信息要检索我的四个 uiimageView uitaiteViewController 中,我无法设置图像,尽管我可以通过登录它们,但将其设置为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;
        }
    }

,如果我尝试将循环方式更改为

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

我得到了此错误uiateviewwrapperveie设定:]:未识别的选择器已发送到实例

我只想知道我是否以错误的方式循环我的意思是我无法通过此循环或正在发生的事情到达它们?

您必须将循环更改为:

 for ( UIView *currentView in cell.contentView.subviews)
   {
      if([currentView isKindOfClass:[UIImageView class]])
      {
           // here Do All the stuff for imageViews
      }
   }

cellForRowAtIndexPath中做所有这些事情并更改图像视图图像以下图像视图的弱实例:

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

我认为这与您的代码无法使用。AS

for(uiimageView *cyr.contentview.subviews in CurrentImageView(

此行将尝试将单元格的所有子视图转换为uiimageView。

您可以将标签设置为所有uiimageview,然后用标签直接访问

的标签

cell.contentview.viewwithtag( yourtag (

并将图像设置为

最新更新