我正在开发图片库应用程序。在集合视图中,我显示了拇指。每次,我滚动集合视图,应用程序读取并再次打开图像。有一段时间后,会有内存警告。我想缓存图像。然后当我滚动集合视图时,应用程序会读取缓存的图像,而不是打开一个新的图像。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
AllViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:IdAllCell forIndexPath:indexPath];
NSArray *arrInfo = [self.arrThangkaInfo objectAtIndex:indexPath.row];
// Cell Image
NSString *thumbImageName = [self getValue:@"thumb_image" forRecord:arrInfo];
NSString *imagePath = [NSString stringWithFormat:@"%@/%@", self.thumbFolder, thumbImageName];
UIImage *originalImage = [UIImage imageWithContentsOfFile:imagePath];
[cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imageView setImage:originalImage];
// Cell Label
NSString *name = [self getValue:@"name" forRecord:arrInfo];
[cell.nameLabel setTextAlignment:NSTextAlignmentCenter];
[cell.nameLabel setTextColor:[UIColor blackColor]];
[cell.nameLabel setBackgroundColor:[UIColor clearColor]];
[cell.nameLabel setText:name];
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}