Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looping through uiimageview in customCell

hello i have product table and product details view for each product i have many images that are downloaded and cached on disk and memory on each time user select a product to check its details i am trying to retrieving cached images and set it up for my Four UIImageView inside the a custom Cell in UITableViewController i am not able to set the images although i can log them through NSLog() function i am using this code:

    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

i just want to know if i am looping in a wrong way what i mean that i am not able to reach them through this loop or what is going on ?

like image 258
Zakaria Darwish Avatar asked May 01 '17 21:05

Zakaria Darwish


1 Answers

You have to change the loop as :

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

Do All this stuff in cellForRowAtIndexPath and to change the imageView image take weak instance of imageView like this :

__weak UIImageView *weakImage = currentImageView;
 [self.imageCache queryDiskCacheForKey:self.currentProduct.mirsaProductUrlImage[indexOfImages]  
    done:^(UIImage *image, SDImageCacheType cacheType) {
                if (image) {
                    weakImage.image =  image;
                }
 }];
like image 193
Ajjjjjjjj Avatar answered Oct 19 '22 09:10

Ajjjjjjjj