ios – 在customCell中循环浏览uiimageview

前端之家收集整理的这篇文章主要介绍了ios – 在customCell中循环浏览uiimageview前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
你好,我有产品表和产品详细信息视图为每个产品我有很多图像,下载和缓存在磁盘和内存,每次用户选择一个产品,以检查其细节我正在检索缓存的图像,并设置为我的四UI ImageView在UITableViewController中的自定义单元格内,我无法设置图像,尽管我可以通过NSLog()函数记录它我正在使用此代码
  1. int index = 0;
  2. int indexOfImages = 1;
  3. self.imageCache = [[SDImageCache alloc] initWithNamespace:@"menuImage"];
  4. for ( UIImageView *currentImageView in cell.contentView.subviews)
  5. {
  6. NSLog(@"the imageindex is: %d",indexOfImages);
  7. NSLog(@"the index is: %d",index);
  8. NSLog(@"the count is: %lu",(unsigned long)[self.currentProduct.mirsaProductUrlImage count]);
  9. if (index < [self.currentProduct.mirsaProductUrlImage count] ) {
  10. [self.imageCache queryDiskCacheForKey:self.currentProduct.mirsaProductUrlImage[indexOfImages]
  11. done:^(UIImage *image,SDImageCacheType cacheType) {
  12. if (image) {
  13. currentImageView.image = image;
  14. }
  15. }];
  16. indexOfImages++;
  17. index++;
  18. }
  19. else
  20. {
  21. break;
  22. }
  23. }

and if i try to change the loop way to this

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

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

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

解决方法

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

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

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

猜你在找的iOS相关文章