你好,我有产品表和产品详细信息视图为每个产品我有很多图像,下载和缓存在磁盘和内存,每次用户选择一个产品,以检查其细节我正在检索缓存的图像,并设置为我的四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; } }];